/* Copyright (c) 2009 Christoph Studer <chstuder@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package tv.studer.smssync;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Date;
import tv.studer.smssync.SmsSyncService.SmsSyncState;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.AlertDialog.Builder;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceCategory;
import android.preference.PreferenceManager;
import android.preference.Preference.OnPreferenceChangeListener;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
/**
* This is the main activity showing the status of the SMS Sync service and
* providing controls to configure it.
*/
public class SmsSync extends PreferenceActivity implements OnPreferenceChangeListener {
private static final int DIALOG_MISSING_CREDENTIALS = 1;
private static final int DIALOG_FIRST_SYNC = 2;
private static final int DIALOG_SYNC_DATA_RESET = 3;
private static final int DIALOG_INVALID_IMAP_FOLDER = 4;
private static final int DIALOG_NEED_FIRST_MANUAL_SYNC = 5;
private static final int DIALOG_ABOUT = 6;
private static final int MENU_INFO = 0;
private static final int MENU_SHARE = 1;
private static final int MENU_MARKET = 2;
private StatusPreference mStatusPref;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
PreferenceManager prefMgr = getPreferenceManager();
addPreferencesFromResource(R.xml.main_screen);
mStatusPref = new StatusPreference(this);
mStatusPref.setSelectable(false);
int sdkLevel = 1;
try {
sdkLevel = Integer.parseInt(Build.VERSION.SDK);
} catch (NumberFormatException nfe) {
// ignore (assume sdkLevel == 1)
}
if (sdkLevel < 3) {
// Older versions don't show the title bar for PreferenceActivity
PreferenceCategory cat = new PreferenceCategory(this);
cat.setOrder(0);
getPreferenceScreen().addPreference(cat);
cat.setTitle(R.string.ui_status_label);
cat.addPreference(mStatusPref);
} else {
// Newer SDK version show the title bar for PreferenceActivity
mStatusPref.setOrder(0);
getPreferenceScreen().addPreference(mStatusPref);
}
Preference pref = prefMgr.findPreference(PrefStore.PREF_LOGIN_USER);
pref.setOnPreferenceChangeListener(this);
pref = prefMgr.findPreference(PrefStore.PREF_IMAP_FOLDER);
pref.setOnPreferenceChangeListener(this);
pref = prefMgr.findPreference(PrefStore.PREF_ENABLE_AUTO_SYNC);
pref.setOnPreferenceChangeListener(this);
pref = prefMgr.findPreference(PrefStore.PREF_LOGIN_PASSWORD);
pref.setOnPreferenceChangeListener(this);
pref = prefMgr.findPreference(PrefStore.PREF_MAX_ITEMS_PER_SYNC);
pref.setOnPreferenceChangeListener(this);
}
@Override
protected void onPause() {
super.onPause();
SmsSyncService.unsetStateChangeListener();
}
@Override
protected void onResume() {
super.onResume();
SmsSyncService.setStateChangeListener(mStatusPref);
updateUsernameLabelFromPref();
updateImapFolderLabelFromPref();
updateMaxItemsPerSync(null);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
menu.add(0, MENU_INFO, 0, R.string.menu_info).setIcon(
android.R.drawable.ic_menu_info_details);
menu.add(0, MENU_SHARE, 1, R.string.menu_share).setIcon(
android.R.drawable.ic_menu_share);
menu.add(0, MENU_MARKET, 2, R.string.menu_market).setIcon(
R.drawable.ic_menu_update);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
super.onOptionsItemSelected(item);
switch (item.getItemId()) {
case MENU_INFO:
// openLink(Consts.URL_INFO_LINK);
showDialog(DIALOG_ABOUT);
return true;
case MENU_SHARE:
share();
return true;
case MENU_MARKET:
openLink(Consts.URL_MARKET_SEARCH);
return true;
}
return false;
}
private void openLink(String link) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(link));
startActivity(intent);
}
private void share() {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("mailto:"));
intent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.share_subject));
intent.putExtra(Intent.EXTRA_TEXT, getString(R.string.share_body,
Consts.URL_MARKET_SEARCH, Consts.URL_INFO_LINK));
startActivity(intent);
}
private void updateUsernameLabelFromPref() {
SharedPreferences prefs = getPreferenceManager().getSharedPreferences();
String username = prefs.getString(PrefStore.PREF_LOGIN_USER,
getString(R.string.ui_login_label));
Preference pref = getPreferenceManager().findPreference(PrefStore.PREF_LOGIN_USER);
pref.setTitle(username);
}
private void updateImapFolderLabelFromPref() {
String imapFolder = PrefStore.getImapFolder(this);
Preference pref = getPreferenceManager().findPreference(PrefStore.PREF_IMAP_FOLDER);
pref.setTitle(imapFolder);
}
private boolean initiateSync() {
if (!PrefStore.isLoginInformationSet(this)) {
showDialog(DIALOG_MISSING_CREDENTIALS);
return false;
} else if (PrefStore.isFirstSync(this)) {
showDialog(DIALOG_FIRST_SYNC);
return false;
} else {
startSync(false);
return true;
}
}
private void startSync(boolean skip) {
Intent intent = new Intent(this, SmsSyncService.class);
if (PrefStore.isFirstSync(this)) {
intent.putExtra(Consts.KEY_SKIP_MESSAGES, skip);
}
startService(intent);
}
private class StatusPreference extends Preference implements
SmsSyncService.StateChangeListener, OnClickListener {
private View mView;
private Button mSyncButton;
private ImageView mStatusIcon;
private TextView mStatusLabel;
private View mSyncDetails;
private TextView mErrorDetails;
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
Android Gmail备份手机短信源码-IT计算机-毕业设计.zip (70个子文件)
Android Gmail备份手机短信源码
1-120Q92025220-L.png 78KB
Android Gmail备份手机短信源码
bin
classes.dex 426KB
SmsBackup.apk 231KB
resources.ap_ 43KB
tv
studer
smssync
SmsSyncService$GeneralErrorException.class 902B
R$layout.class 429B
R$id.class 705B
R$drawable.class 650B
SmsSyncService$1.class 3KB
PrefStore.class 6KB
CursorToMessage$ConversionResult.class 565B
SmsSync$3.class 1KB
CursorToMessage$PersonRecord.class 630B
SmsConsts.class 959B
SmsSync$6.class 687B
R$plurals.class 409B
R$attr.class 337B
SmsSync$4.class 947B
SmsSync$StatusPreference.class 4KB
R.class 712B
R$array.class 410B
Alarms.class 2KB
SmsSyncService.class 11KB
SmsSync$StatusPreference$1.class 6KB
SmsSync$5.class 901B
SmsSync$1.class 901B
R$string.class 3KB
SmsBroadcastReceiver.class 967B
Consts.class 759B
CursorToMessage.class 9KB
R$xml.class 389B
SmsSync$2.class 948B
R$color.class 501B
SmsSync.class 12KB
SmsSyncService$AuthenticationErrorException.class 721B
SmsSyncService$StateChangeListener.class 435B
SmsSyncService$SmsSyncState.class 1KB
res
drawable-ldpi
icon.png 2KB
drawable-hdpi
ic_launcher_smssync2.png 4KB
ic_idle.png 1KB
ic_done.png 2KB
icon.png 4KB
ic_error.png 2KB
ic_menu_update.png 3KB
ic_launcher_smssync.png 4KB
ic_syncing.png 2KB
values
colors.xml 246B
strings.xml 6KB
arrays.xml 257B
drawable-mdpi
icon.png 3KB
layout
about_dialog.xml 397B
status.xml 3KB
xml
main_screen.xml 2KB
.svn
all-wcprops 204B
prop-base
props
tmp
prop-base
props
text-base
text-base
main_screen.xml.svn-base 2KB
entries 366B
assets
default.properties 364B
gen
tv
studer
smssync
R.java 7KB
src
tv
studer
smssync
Alarms.java 2KB
PrefStore.java 8KB
CursorToMessage.java 10KB
SmsConsts.java 2KB
Consts.java 2KB
SmsSyncService.java 20KB
SmsBroadcastReceiver.java 1KB
SmsSync.java 28KB
.project 845B
.classpath 336B
lib
imapstore.jar 391KB
AndroidManifest.xml 1KB
共 70 条
- 1
资源评论
芝麻粒儿
- 粉丝: 5w+
- 资源: 2万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功