Skip to content
This repository has been archived by the owner on Feb 20, 2019. It is now read-only.

Commit

Permalink
AcitivtyEditor new thread
Browse files Browse the repository at this point in the history
  • Loading branch information
heruoxin committed Feb 21, 2015
1 parent 3ec24dd commit 32169c9
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 20 deletions.
6 changes: 2 additions & 4 deletions TinyClipboards.iml
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" type="JAVA_MODULE" version="4">
<module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="java-gradle" name="Java-Gradle">
<configuration>
<option name="BUILD_FOLDER_PATH" value="$MODULE_DIR$/build" />
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/build/classes/main" />
<output-test url="file://$MODULE_DIR$/build/classes/test" />
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.gradle" />
Expand Down
4 changes: 3 additions & 1 deletion app/app.iml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" type="JAVA_MODULE" version="4">
<module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="TinyClipboards" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="android-gradle" name="Android-Gradle">
<configuration>
Expand All @@ -9,6 +9,7 @@
<facet type="android" name="Android">
<configuration>
<option name="SELECTED_BUILD_VARIANT" value="debug" />
<option name="SELECTED_TEST_ARTIFACT" value="_android_test_" />
<option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
<option name="COMPILE_JAVA_TASK_NAME" value="compileDebugSources" />
<option name="ASSEMBLE_TEST_TASK_NAME" value="assembleDebugTest" />
Expand All @@ -24,6 +25,7 @@
</component>
<component name="NewModuleRootManager" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/build/intermediates/classes/debug" />
<output-test url="file://$MODULE_DIR$/build/intermediates/classes/test/debug" />
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/debug" isTestSource="false" generated="true" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,16 @@ public class ActivityEditor extends ActionBarActivity {
private String oldText;
private EditText editText;
private InputMethodManager inputMethodManager;
private ClipboardManager cb;
private Context context;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_editor);
cb = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
context = this.getBaseContext();

Intent intent = getIntent();
oldText = intent.getStringExtra(Intent.EXTRA_TEXT);
if (oldText == null) {
Expand Down Expand Up @@ -55,14 +60,14 @@ public void onFocusChange(View v, boolean hasFocus) {
if ("".equals(oldText)) {
titleText = getString(R.string.title_activity_editor);
}
getSupportActionBar().setTitle(titleText);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
setTaskDescription(new ActivityManager.TaskDescription(
titleText,
BitmapFactory.decodeResource(getResources(), R.drawable.icon),
getResources().getColor(R.color.primary)
));
}
getSupportActionBar().setTitle(titleText);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
setTaskDescription(new ActivityManager.TaskDescription(
titleText,
BitmapFactory.decodeResource(getResources(), R.drawable.icon),
getResources().getColor(R.color.primary)
));
}
}

@Override
Expand Down Expand Up @@ -119,8 +124,17 @@ public boolean onOptionsItemSelected(MenuItem item) {
}

private void deleteText() {
Storage db = Storage.getInstance(this);
db.modifyClip(oldText, null, Storage.MAIN_ACTIVITY_VIEW);

new Thread(
new Runnable() {
@Override
public void run() {
Storage db = Storage.getInstance(context);
db.modifyClip(oldText, null, Storage.MAIN_ACTIVITY_VIEW);
}
}
).start();

finishAndRemoveTaskWithToast(getString(R.string.toast_deleted));
}

Expand All @@ -133,17 +147,27 @@ private void shareText() {
}

private void saveText() {
String newText = editText.getText().toString();
final String newText = editText.getText().toString();
String toastMessage;
if (oldText.equals(newText)) {
finishAndRemoveTaskWithToast(getString(R.string.toast_no_saved));
return;
}
Storage db = Storage.getInstance(this);
db.modifyClip(oldText, null, Storage.MAIN_ACTIVITY_VIEW);

new Thread(
new Runnable() {
@Override
public void run() {
Storage db = Storage.getInstance(context);
db.modifyClip(oldText, null, Storage.MAIN_ACTIVITY_VIEW);
if (newText != null && !"".equals(newText)) {
cb.setText(newText);
}
}
}
).start();

if (newText != null && !"".equals(newText)) {
ClipboardManager cb = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
cb.setText(newText);
toastMessage = getString(R.string.toast_saved);
} else {
toastMessage = getString(R.string.toast_deleted);
Expand Down

0 comments on commit 32169c9

Please sign in to comment.