-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
225 additions
and
19 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,32 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.naman14.arcade" > | ||
package="com.naman14.arcade"> | ||
|
||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> | ||
<uses-permission android:name="android.permission.INTERNET"/> | ||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> | ||
<uses-permission android:name="android.permission.INTERNET" /> | ||
|
||
<application | ||
android:name=".ArcadeApp" | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:largeHeap="true" | ||
android:supportsRtl="true" | ||
android:theme="@style/AppTheme" | ||
android:name=".ArcadeApp"> | ||
android:theme="@style/AppTheme"> | ||
<activity | ||
android:name=".MainActivity" | ||
android:label="@string/app_name" | ||
android:theme="@style/AppTheme.NoActionBar" > | ||
android:theme="@style/AppTheme.FullScreen"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
|
||
<activity | ||
android:name=".SettingsActivity" | ||
android:theme="@style/AppTheme.NoActionBar" /> | ||
</application> | ||
|
||
</manifest> |
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
106 changes: 106 additions & 0 deletions
106
app/src/main/java/com/naman14/arcade/SettingsActivity.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package com.naman14.arcade; | ||
|
||
import android.content.Context; | ||
import android.content.DialogInterface; | ||
import android.content.SharedPreferences; | ||
import android.os.Bundle; | ||
import android.preference.Preference; | ||
import android.preference.PreferenceFragment; | ||
import android.preference.PreferenceManager; | ||
import android.support.annotation.Nullable; | ||
import android.support.v7.app.AlertDialog; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.support.v7.widget.Toolbar; | ||
import android.text.InputType; | ||
import android.view.MenuItem; | ||
import android.widget.EditText; | ||
|
||
/** | ||
* Created by naman on 13/05/16. | ||
*/ | ||
public class SettingsActivity extends AppCompatActivity { | ||
|
||
@Override | ||
protected void onCreate(@Nullable Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_settings); | ||
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); | ||
setSupportActionBar(toolbar); | ||
getSupportActionBar().setDisplayHomeAsUpEnabled(true); | ||
getSupportActionBar().setTitle("Settings"); | ||
getFragmentManager().beginTransaction().replace(R.id.container, new SettingsFragment()).commit(); | ||
} | ||
|
||
@Override | ||
public boolean onOptionsItemSelected(MenuItem item) { | ||
if (item.getItemId() == android.R.id.home) | ||
super.onBackPressed(); | ||
return super.onOptionsItemSelected(item); | ||
} | ||
|
||
public static class SettingsFragment extends PreferenceFragment implements SharedPreferences.OnSharedPreferenceChangeListener { | ||
|
||
SharedPreferences preferences; | ||
|
||
@Override | ||
public void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
addPreferencesFromResource(R.xml.preferences); | ||
|
||
preferences = PreferenceManager.getDefaultSharedPreferences(getActivity()); | ||
findPreference("preference_iterations").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { | ||
@Override | ||
public boolean onPreferenceClick(Preference preference) { | ||
showEditDialog(getActivity(), preferences, "Number of iterations", "Iterations", "preference_iterations"); | ||
return true; | ||
} | ||
}); | ||
findPreference("preference_style_weight").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { | ||
@Override | ||
public boolean onPreferenceClick(Preference preference) { | ||
showEditDialog(getActivity(), preferences, "Style weight", "Style weight", "preference_style_weight"); | ||
return true; | ||
} | ||
}); | ||
findPreference("preference_content_weight").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { | ||
@Override | ||
public boolean onPreferenceClick(Preference preference) { | ||
showEditDialog(getActivity(), preferences, "Content weight", "Content weight", "preference_content_weight"); | ||
return true; | ||
} | ||
}); | ||
findPreference("preference_defaults").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { | ||
@Override | ||
public boolean onPreferenceClick(Preference preference) { | ||
preferences.edit().putInt("preference_iterations", 15).apply(); | ||
preferences.edit().putInt("preference_style_weight", 200).apply(); | ||
preferences.edit().putInt("preference_content_weight", 20).apply(); | ||
preferences.edit().putInt("preference_image_size", 128).apply(); | ||
return true; | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { | ||
findPreference(key).setSummary(String.valueOf(preferences.getInt(key, -1))); | ||
} | ||
} | ||
|
||
private static void showEditDialog(Context context, final SharedPreferences preferences, String title, String hint, final String key) { | ||
AlertDialog.Builder alertDialog = new AlertDialog.Builder(context); | ||
alertDialog.setTitle(title); | ||
final EditText input = new EditText(context); | ||
input.setInputType(InputType.TYPE_NUMBER_FLAG_SIGNED); | ||
input.setHint(hint); | ||
input.setText(String.valueOf(preferences.getInt(key, -1))); | ||
alertDialog.setView(input); | ||
alertDialog.setPositiveButton("Save", | ||
new DialogInterface.OnClickListener() { | ||
public void onClick(DialogInterface dialog, int which) { | ||
preferences.edit().putInt(key, Integer.parseInt(input.getText().toString())).apply(); | ||
} | ||
}); | ||
alertDialog.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:orientation="vertical"> | ||
|
||
<android.support.v7.widget.Toolbar | ||
android:id="@+id/toolbar" | ||
android:layout_width="match_parent" | ||
android:layout_height="?attr/actionBarSize" | ||
android:background="@color/colorPrimary" | ||
android:theme="@style/Theme.AppCompat" /> | ||
|
||
<FrameLayout | ||
android:id="@+id/container" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" /> | ||
|
||
</LinearLayout> |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<string-array name="pref_image_size_entries"> | ||
<item>128</item> | ||
<item>256</item> | ||
<item>512</item> | ||
</string-array> | ||
|
||
<string-array name="pref_image_size_values"> | ||
<item>128</item> | ||
<item>256</item> | ||
<item>512</item> | ||
</string-array> | ||
|
||
</resources> |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
<PreferenceCategory android:title="General"> | ||
|
||
<ListPreference | ||
android:defaultValue="128" | ||
android:entries="@array/pref_image_size_entries" | ||
android:entryValues="@array/pref_image_size_values" | ||
android:key="preference_image_size" | ||
android:summary="The size of the output image to be generated" | ||
android:title="Output Image Size" /> | ||
|
||
<Preference | ||
android:defaultValue="15" | ||
android:key="preference_iterations" | ||
android:title="Number of iterations" /> | ||
|
||
<Preference | ||
android:defaultValue="200" | ||
android:key="preference_style_weight" | ||
android:title="Style weight" /> | ||
|
||
<Preference | ||
android:defaultValue="20" | ||
android:key="preference_content_weight" | ||
android:title="Content weight" /> | ||
|
||
<Preference | ||
android:key="preference_defaults" | ||
android:title="Reset to defaults" /> | ||
|
||
</PreferenceCategory> | ||
</PreferenceScreen> |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.naman14.arcade.library"> | ||
|
||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> | ||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> | ||
|
||
<application android:allowBackup="true" | ||
<application | ||
android:allowBackup="true" | ||
android:label="@string/app_name" | ||
android:supportsRtl="true" | ||
> | ||
</application> | ||
android:largeHeap="true" | ||
android:supportsRtl="true"></application> | ||
|
||
</manifest> |
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
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
Oops, something went wrong.