move copyToClipboard() to CommonActivity

This commit is contained in:
Andrew Dolgov 2012-06-25 00:00:14 +04:00
parent 3d39b03a60
commit 7b10e95213
3 changed files with 17 additions and 28 deletions

View File

@ -7,6 +7,7 @@ import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentActivity;
import android.util.Log; import android.util.Log;
import android.widget.Toast;
public class CommonActivity extends FragmentActivity { public class CommonActivity extends FragmentActivity {
private final String TAG = this.getClass().getSimpleName(); private final String TAG = this.getClass().getSimpleName();
@ -72,5 +73,19 @@ public class CommonActivity extends FragmentActivity {
public int getOrientation() { public int getOrientation() {
return getWindowManager().getDefaultDisplay().getOrientation(); return getWindowManager().getDefaultDisplay().getOrientation();
} }
public void copyToClipboard(String str) {
if (android.os.Build.VERSION.SDK_INT < 11) {
@SuppressWarnings("deprecation")
android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
clipboard.setText(str);
} else {
android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
clipboard.setText(str);
}
Toast toast = Toast.makeText(this, R.string.text_copied_to_clipboard, Toast.LENGTH_SHORT);
toast.show();
}
} }

View File

@ -2245,21 +2245,6 @@ public class MainActivity extends CommonActivity implements OnlineServices {
initMainMenu(); initMainMenu();
} }
@Override
public void copyToClipboard(String str) {
if (android.os.Build.VERSION.SDK_INT < 11) {
@SuppressWarnings("deprecation")
android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
clipboard.setText(str);
} else {
android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
clipboard.setText(str);
}
Toast toast = Toast.makeText(MainActivity.this, R.string.text_copied_to_clipboard, Toast.LENGTH_SHORT);
toast.show();
}
@Override @Override
public void restart() { public void restart() {
Intent refresh = new Intent(MainActivity.this, MainActivity.class); Intent refresh = new Intent(MainActivity.this, MainActivity.class);

View File

@ -1041,19 +1041,8 @@ public class OfflineActivity extends CommonActivity implements
} }
if (article != null) { if (article != null) {
if (android.os.Build.VERSION.SDK_INT < 11) { copyToClipboard(article.getString(article.getColumnIndex("link")));
@SuppressWarnings("deprecation")
android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
clipboard.setText(article.getString(article.getColumnIndex("link")));
} else {
android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
clipboard.setText(article.getString(article.getColumnIndex("link")));
}
article.close(); article.close();
Toast toast = Toast.makeText(OfflineActivity.this, R.string.text_copied_to_clipboard, Toast.LENGTH_SHORT);
toast.show();
} }
} }
return true; return true;