SettingsActivity.java 6.0 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/*
 * Copyright (c) 2012-2013 NetEase, Inc. and other contributors
 *
 *  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.
 *
 */
K
kevinkong 已提交
17 18
package com.netease.qa.emmagee.activity;

A
andrewleo2013 已提交
19
import java.io.FileInputStream;
K
kevinkong 已提交
20 21
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
A
andrewleo2013 已提交
22
import java.util.Properties;
K
kevinkong 已提交
23 24 25 26 27 28

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
29
import android.view.Window;
K
kevinkong 已提交
30 31
import android.view.View.OnClickListener;
import android.widget.CheckBox;
32 33
import android.widget.ImageView;
import android.widget.LinearLayout;
34 35 36
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;
K
kevinkong 已提交
37 38

import com.netease.qa.emmagee.R;
A
andrewleo2013 已提交
39
import com.netease.qa.emmagee.utils.EncryptData;
K
kevinkong 已提交
40

41 42
/**
 * Setting Page of Emmagee
A
andrewleo2013 已提交
43
 * 
A
andrewleo 已提交
44
 * @author andrewleo
45
 */
K
kevinkong 已提交
46 47
public class SettingsActivity extends Activity {

48
	private static final String LOG_TAG = "Emmagee-" + SettingsActivity.class.getSimpleName();
A
andrewleo2013 已提交
49

K
kevinkong 已提交
50
	private CheckBox chkFloat;
51
	private TextView tvTime;
52
	private String time;
K
kevinkong 已提交
53
	private String settingTempFile;
54 55
	private LinearLayout about;
	private LinearLayout mailSettings;
K
kevinkong 已提交
56 57 58 59 60

	@Override
	public void onCreate(Bundle savedInstanceState) {
		Log.i(LOG_TAG, "onCreate");
		super.onCreate(savedInstanceState);
61
		requestWindowFeature(Window.FEATURE_NO_TITLE);
K
kevinkong 已提交
62 63
		setContentView(R.layout.settings);

64
		Properties properties = new Properties();
A
andrewleo2013 已提交
65
		final EncryptData des = new EncryptData("emmagee");
K
kevinkong 已提交
66
		Intent intent = this.getIntent();
67
		settingTempFile = getBaseContext().getFilesDir().getPath() + "\\EmmageeSettings.properties";
A
andrewleo2013 已提交
68

K
kevinkong 已提交
69
		chkFloat = (CheckBox) findViewById(R.id.floating);
70
		tvTime = (TextView) findViewById(R.id.time);
71 72
		about = (LinearLayout) findViewById(R.id.about);
		mailSettings = (LinearLayout) findViewById(R.id.mail_settings);
73
		SeekBar timeBar = (SeekBar) findViewById(R.id.timeline);
A
andrewleo2013 已提交
74

75 76
		ImageView btnSave = (ImageView) findViewById(R.id.btn_set);
		ImageView goBack = (ImageView) findViewById(R.id.go_back);
K
kevinkong 已提交
77 78
		boolean floatingTag = true;

79
		btnSave.setImageResource(R.drawable.actionbar_bg);
K
kevinkong 已提交
80
		try {
A
andrewleo2013 已提交
81
			properties.load(new FileInputStream(settingTempFile));
82 83
			String interval = (null == properties.getProperty("interval")) ? "" : properties.getProperty("interval").trim();
			String isfloat = (null == properties.getProperty("isfloat")) ? "" : properties.getProperty("isfloat").trim();
A
andrewleo2013 已提交
84 85
			time = "".equals(interval) ? "5" : interval;
			floatingTag = "false".equals(isfloat) ? false : true;
K
kevinkong 已提交
86
		} catch (FileNotFoundException e) {
A
andrewleo2013 已提交
87
			Log.e(LOG_TAG, "FileNotFoundException: " + e.getMessage());
K
kevinkong 已提交
88
			e.printStackTrace();
89 90
		} catch (Exception e) {
			Log.e(LOG_TAG, "Exception: " + e.getMessage());
K
kevinkong 已提交
91 92
			e.printStackTrace();
		}
93
		tvTime.setText(time);
K
kevinkong 已提交
94
		chkFloat.setChecked(floatingTag);
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
		timeBar.setProgress(Integer.parseInt(time));
		timeBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
			@Override
			public void onProgressChanged(SeekBar arg0, int arg1, boolean arg2) {
				tvTime.setText(Integer.toString(arg1 + 1));
			}

			@Override
			public void onStartTrackingTouch(SeekBar arg0) {
			}

			@Override
			public void onStopTrackingTouch(SeekBar arg0) {
				// when tracking stoped, update properties file
				int interval = arg0.getProgress() + 1;
				try {
					Properties properties = new Properties();
					properties.load(new FileInputStream(settingTempFile));   
					properties.setProperty("interval", Integer.toString(interval));
					FileOutputStream fos = new FileOutputStream(settingTempFile);
					properties.store(fos, "Setting Data");
					fos.close();
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
A
andrewleo2013 已提交
122

123 124 125 126 127
		goBack.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View arg0) {
				SettingsActivity.this.finish();
				Intent intent = new Intent();
128
				intent.setClass(SettingsActivity.this, MainPageActivity.class);
129 130 131
				startActivity(intent);
			}
		});
132

133 134 135 136
		mailSettings.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View arg0) {
				Intent intent = new Intent();
137 138
				intent.setClass(SettingsActivity.this, MailSettingsActivity.class);
				startActivity(intent);
139 140 141 142 143 144 145 146
			}
		});

		about.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View arg0) {
				Intent intent = new Intent();
				intent.setClass(SettingsActivity.this, AboutActivity.class);
147
				startActivity(intent);
148 149 150 151 152 153 154 155
			}
		});

		chkFloat.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View arg0) {
				try {
					Properties properties = new Properties();
156 157
					properties.load(new FileInputStream(settingTempFile));  
					properties.setProperty("isfloat", chkFloat.isChecked() ? "true" : "false");
158 159 160 161 162 163 164 165 166
					FileOutputStream fos = new FileOutputStream(settingTempFile);
					properties.store(fos, "Setting Data");
					fos.close();
				} catch (Exception e) {
					e.printStackTrace();
					chkFloat.setChecked(chkFloat.isChecked() ? false : true);
				}
			}
		});
K
kevinkong 已提交
167 168 169 170 171 172 173 174 175 176 177 178 179
	}

	@Override
	public void finish() {
		super.finish();
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
	}

	/**
A
andrewleo2013 已提交
180
	 * is input a number.
A
andrewleo2013 已提交
181
	 * 
K
kevinkong 已提交
182 183
	 * @param inputStr
	 *            input string
A
andrewleo2013 已提交
184
	 * @return true is numeric
K
kevinkong 已提交
185 186 187 188 189 190 191 192 193 194 195
	 */
	private boolean isNumeric(String inputStr) {
		for (int i = inputStr.length(); --i >= 0;) {
			if (!Character.isDigit(inputStr.charAt(i))) {
				return false;
			}
		}
		return true;
	}

}