package com.itheima.mobilesafe;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

public class LostFindActivity extends Activity {
	private SharedPreferences sp;
	private TextView tv_safenumber;
	private ImageView iv_protecting;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		sp = getSharedPreferences("config", MODE_PRIVATE);
		// ÅÐ¶ÏÒ»ÏÂ£¬ÊÇ·ñ×ö¹ýÉèÖÃÏòµ¼£¬Èç¹ûÃ»ÓÐ×ö¹ý£¬¾ÍÌø×ªµ½ÉèÖÃÏòµ¼Ò³ÃæÈ¥ÉèÖÃ£¬·ñÔò¾ÍÁô×Åµ±Ç°µÄÒ³Ãæ
		boolean configed = sp.getBoolean("configed", false);
		if (configed) {
			// ¾ÍÔÚÊÖ»ú·ÀµÁÒ³Ãæ
			setContentView(R.layout.activity_lost_find);
			tv_safenumber = (TextView) findViewById(R.id.tv_safenumber);
			iv_protecting = (ImageView) findViewById(R.id.iv_protecting);
			// µÃµ½ÎÒÃÇÉèÖÃµÄ°²È«ºÅÂë
			String safenumber = sp.getString("safeNumber", "");
			tv_safenumber.setText(safenumber);
			// ÉèÖÃ·ÀµÁ±£»¤µÄ×´Ì¬
			boolean protecting = sp.getBoolean("protecting", false);
			if (protecting) {
				// ÒÑ¾­¿ªÆô·ÀµÁ±£»¤
				iv_protecting.setImageResource(R.drawable.lock);
			} else {
				// Ã»ÓÐ¿ªÆô·ÀµÁ±£»¤
				iv_protecting.setImageResource(R.drawable.unlock);
			}
		} else {
			// »¹Ã»ÓÐ×ö¹ýÉèÖÃÏòµ¼
			Intent intent = new Intent(this, Setup1Activity.class);
			startActivity(intent);
			// ¹Ø±Õµ±Ç°Ò³Ãæ
			finish();
		}
	}

	public void reEnterSetup(View view) {
		Intent intent = new Intent(LostFindActivity.this, Setup1Activity.class);
		startActivity(intent);
		finish();
	}
}
