Last active
February 25, 2017 20:09
-
-
Save avipars/16fcbb01f38b9a6fb13d6791298695ad to your computer and use it in GitHub Desktop.
Android Starter Code: https://medium.com/@aviparshan/android-starter-code-e58f1b94685d
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.aviparshan.flashlight; | |
import android.app.Dialog; | |
import android.os.Bundle; | |
import android.support.annotation.NonNull; | |
import android.support.v4.app.DialogFragment; | |
import android.support.v7.app.AppCompatActivity; | |
import com.afollestad.materialdialogs.MaterialDialog; | |
public class AboutDialog extends DialogFragment { | |
public static void show(AppCompatActivity context) { | |
AboutDialog dialog = new AboutDialog(); | |
dialog.show(context.getSupportFragmentManager(), "[ABOUT_DIALOG]"); | |
} | |
@NonNull | |
@Override | |
public Dialog onCreateDialog(Bundle savedInstanceState) { | |
return new MaterialDialog.Builder(getActivity()) | |
.title(R.string.about) | |
.positiveText(R.string.dismiss) | |
.content(R.string.about_body, true) | |
.contentLineSpacing(1.6f) | |
.build(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void composeEmail() { | |
//Used in CPU Info app I made: https://play.google.com/store/apps/details?id=com.aviparshan.appinfo | |
String PhoneModel = android.os.Build.MODEL; | |
String AndroidVersion = android.os.Build.VERSION.RELEASE; | |
int API = Build.VERSION.SDK_INT; | |
String Language = Locale.getDefault().getISO3Language(); | |
int versionCode = BuildConfig.VERSION_CODE; | |
String versionName = BuildConfig.VERSION_NAME; | |
Intent intent = new Intent(Intent.ACTION_SENDTO); | |
intent.setData(Uri.parse("mailto:")); | |
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"[email protected]"}); | |
intent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.app_name)); | |
intent.putExtra(Intent.EXTRA_TEXT, "App Information \n" + | |
"Phone Model: " + PhoneModel + "\nAndroid Version: " + AndroidVersion + "\nAPI Level: " + API + "\nVersion Code: " + versionCode + "\nVersion Name: " + versionName + "\nLanguage: "+ Language); | |
try { | |
//startActivity(Intent.createChooser(intent, "Send mail...")); | |
startActivity(intent); | |
} catch (android.content.ActivityNotFoundException ex) { | |
Toast.makeText(MainActivity.this, R.string.rate_error, Toast.LENGTH_SHORT).show(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apply plugin: 'com.android.application' | |
android { | |
compileSdkVersion 25 | |
buildToolsVersion "25.0.2" | |
defaultConfig { | |
applicationId "com.aviparshan.flashlight" | |
minSdkVersion 17 | |
targetSdkVersion 25 | |
versionCode 1 | |
versionName "1.0.0" | |
resConfig("en") | |
} | |
signingConfigs { | |
release | |
Key { | |
keyAlias 'Key' | |
keyPassword 'Pass' | |
storeFile file('C:/Users/keystore.jks') | |
storePassword 'Pass2' | |
} | |
} | |
buildTypes { | |
debug { | |
minifyEnabled false | |
} | |
release { | |
minifyEnabled true | |
shrinkResources true | |
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | |
} | |
} | |
} | |
dependencies { | |
compile 'com.android.support:appcompat-v7:25.2.0' | |
compile 'com.android.support:design:25.2.0' | |
compile 'com.afollestad.material-dialogs:core:0.9.3.0' | |
} | |
def Properties props = new Properties() | |
def propFile = new File('signing.properties') | |
if (propFile.canRead()) { | |
props.load(new FileInputStream(propFile)) | |
if (props != null && props.containsKey('STORE_FILE') && props.containsKey('STORE_PASSWORD') && | |
props.containsKey('KEY_ALIAS') && props.containsKey('KEY_PASSWORD')) { | |
android.signingConfigs.release.storeFile = file(props['STORE_FILE']) | |
android.signingConfigs.release.storePassword = props['STORE_PASSWORD'] | |
android.signingConfigs.release.keyAlias = props['KEY_ALIAS'] | |
android.signingConfigs.release.keyPassword = props['KEY_PASSWORD'] | |
} else { | |
println 'signing.properties found but some entries are missing' | |
android.buildTypes.release.signingConfig = null | |
} | |
} else { | |
println 'signing.properties not found' | |
android.buildTypes.release.signingConfig = null | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public boolean onCreateOptionsMenu(Menu menu) { | |
getMenuInflater().inflate(R.menu.menu, menu); | |
return true; | |
} | |
@Override | |
public boolean onOptionsItemSelected(MenuItem item) { | |
switch (item.getItemId()) { | |
case R.id.about: | |
AboutDialog.show(this); | |
return true; | |
case R.id.feedback: | |
composeEmail(); | |
return true; | |
case R.id.rate: | |
goToMyApp(this); | |
return true; | |
default: | |
return super.onOptionsItemSelected(item); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<menu xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto"> | |
<item | |
android:id="@+id/about" | |
android:title="@string/about" | |
app:showAsAction="never"/> | |
<item | |
android:id="@+id/feedback" | |
android:title="@string/feedback" | |
app:showAsAction="never" | |
/> | |
<item | |
android:id="@+id/rate" | |
android:title="@string/rate_app" | |
app:showAsAction="ifRoom" | |
android:icon="@drawable/ic_star_black_24dp" /> | |
</menu> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void goToMyApp(Context context) { | |
try { | |
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id=" + getPackageName()))); | |
} catch (ActivityNotFoundException e1) { | |
Toast.makeText(this, R.string.rate_error, Toast.LENGTH_SHORT).show(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- About --> | |
<string name="about">About</string> | |
<string name="about_body"><![CDATA[ | |
<b>Avi Parshan</b> created this app, Check his website and social media:<br/> | |
<a href=\'http://aviparshan.com\'>Website</a> | |
<a href=\'https://twitter.com/aviinfinity\'>Twitter</a> | |
<a href=\'https://www.youtube.com/channel/UCYzocrbgFApPAGhq7PAw9Gw\'>YouTube</a> | |
<a href=\'https://www.linkedin.com/in/aviparshan\'>LinkedIn</a> | |
<a href=\'https://www.facebook.com/appdeomcracy\'>Facebook</a> | |
]]></string> | |
<string name="dismiss">Dismiss</string> | |
<string name="feedback">Contact Me</string> | |
<string name="rate_app">Rate App</string> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment