Skip to content
Permalink
Browse files

QR Support is working

  • Loading branch information...
michaelachmann committed Feb 4, 2017
1 parent ce970f7 commit 576f57b1fa1c843ff3ecf70d32987898d84a35d3
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />
<option value="$PROJECT_DIR$/app" />
</set>
</option>
<option name="resolveModulePerSourceSet" value="false" />
</GradleProjectSettings>
</option>
</component>
</project>
@@ -15,19 +15,25 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

import android.app.Activity;
import android.app.Dialog;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.Point;
import android.net.Uri;
import android.preference.PreferenceManager;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ProgressBar;
@@ -81,7 +87,7 @@ protected void onCreate(Bundle savedInstanceState) {
final ImageButton openLinkButton = (ImageButton) findViewById(R.id.openLinkButton);
final ImageButton copyLinkButton = (ImageButton) findViewById(R.id.copyLinkButton);
final ProgressBar progressBar = (ProgressBar) findViewById(R.id.progressBar);
final ImageView qrCodeImageView = (ImageView) findViewById(R.id.imageViewQrCode);
final ImageButton qrCodeButton = (ImageButton) findViewById(R.id.qrCodeButton);

// Setting up Toolbar
Toolbar mainToolbar = (Toolbar) findViewById(R.id.main_toolbar);
@@ -131,22 +137,15 @@ public void onResponse(String response) {
// We set the shortened URL as Label
viewShortenedUrl.setText(shortUrl);

// Generate QR-Code for ShortLink
Bitmap qrCode = QRCode.from(shortUrl)
.withSize(250,250)
.withColor(0xFF000000, 0x00000000)
.bitmap();

// Set QRCode ad Image
qrCodeImageView.setImageBitmap(qrCode);

// Now we hide the loading-spinner and set the Buttons and Texts as vissible
progressBar.setVisibility(View.GONE);
viewShortenedUrl.setVisibility(View.VISIBLE);
shareButton.setVisibility(View.VISIBLE);
openLinkButton.setVisibility(View.VISIBLE);
copyLinkButton.setVisibility(View.VISIBLE);
qrCodeImageView.setVisibility(View.VISIBLE);
qrCodeButton.setVisibility(View.VISIBLE);


}
@@ -245,6 +244,32 @@ public void shareLink(View view) {

}

public void showQRCode(View view){

Dialog qrCodeDialog = new Dialog(this);
qrCodeDialog.getWindow()
.requestFeature(Window.FEATURE_NO_TITLE);

qrCodeDialog.setContentView(getLayoutInflater().inflate(R.layout.qr_popup
, null));

final ImageView qrCodeImageView = (ImageView) qrCodeDialog.findViewById(R.id.qrCodeImageView);


// Generate QR-Code for ShortLink
Bitmap qrCode = QRCode.from(shortUrl)
.withSize(800,800)
.withColor(0xFF000000, 0x00000000)
.bitmap();

// Set QRCode ad Image
qrCodeImageView.setImageBitmap(qrCode);

qrCodeDialog.show();

}


public void copyLink(View view){
ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("Short Link", shortUrl);
@@ -158,7 +158,7 @@ public boolean onOptionsItemSelected(MenuItem item) {

case R.id.action_bug:

String url = "https://github.com/michaelachmann/LnkShortener/issues/new";
String url = "https://github.com/michaelachmann/LnkShortener/issues/";
Intent intentBug = new Intent(Intent.ACTION_VIEW);
intentBug.setData(Uri.parse(url));
startActivity(intentBug);
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M3,11H5V13H3V11M11,5H13V9H11V5M9,11H13V15H11V13H9V11M15,11H17V13H19V11H21V13H19V15H21V19H19V21H17V19H13V21H11V17H15V15H17V13H15V11M19,19V15H17V19H19M15,3H21V9H15V3M17,5V7H19V5H17M3,3H9V9H3V3M5,5V7H7V5H5M3,15H9V21H3V15M5,17V19H7V17H5Z"/>
</vector>
@@ -104,6 +104,21 @@
android:padding="5dp"
android:scaleType="fitCenter"
android:layout_weight="1" />
<ImageButton
android:id="@+id/qrCodeButton"
app:srcCompat="@drawable/ic_qrcode"
android:background="@android:color/transparent"
android:visibility="gone"
android:layout_height="80dp"
android:layout_width="80dp"
android:textSize="48sp"
android:textStyle="normal|bold"
android:layout_marginLeft="23dp"
android:onClick="showQRCode"
android:adjustViewBounds="true"
android:padding="5dp"
android:scaleType="fitCenter"
android:layout_weight="1" />

</LinearLayout>

@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical" android:layout_width="match_parent"
android:gravity="center"
android:layout_height="match_parent">

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@mipmap/ic_image"
android:id="@+id/qrCodeImageView" />
</LinearLayout>
@@ -4,10 +4,11 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
>

<!-- History Button is yet hidden since implementation is postponed to 1.2.0 release -->
<item android:id="@+id/action_history"
android:title="@string/action_history"
app:showAsAction="always"

android:visible="false"
android:icon="@drawable/ic_history_white_24dp"
/>

@@ -16,4 +16,6 @@
<string name="error_misc">Bitte überprüfe deine Polr Einstellungen!</string>
<string name="settings_api_key">API-Schlüssel</string>
<string name="settings_domain">Domain</string>
<string name="action_history">Verlauf</string>
<string name="action_bug">Bug melden</string>
</resources>

0 comments on commit 576f57b

Please sign in to comment.
You can’t perform that action at this time.