import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import kpapptime.talk.school.pase.ListInfo.listNote;
import kpapptime.talk.school.pase.RSSParse;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.location.Location;
import android.location.LocationManager;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.SimpleAdapter;
public class GpslistActivity extends Activity {
 private static final String TAG = "MainActivity";
 private ArrayList<HashMap<String, String>> list_board = new ArrayList<HashMap<String, String>>();
    private SimpleAdapter sa;
    private ArrayList<String> contents;
    private ListView lv;
    private int sel_position;
    private int type;
    int value=0;
    private Context context;
    
    SharedPreferences pref;
    
    
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  requestWindowFeature(Window.FEATURE_NO_TITLE);
     setContentView(R.layout.gpslist);
     
     Intent intent = getIntent();
     type = intent.getIntExtra("type", 0);
     
     context = GpslistActivity.this;
     LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE); 
  Location location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
  double lat = location.getLatitude();
  double lng = location.getLongitude();
     contents = new ArrayList<String>();
        lv = (ListView)findViewById(R.id.listView1);
        RSSParse rss = new RSSParse(contents);
        sa = new SimpleAdapter(this, list_board, R.layout.list_now, new String[]{listNote.NAME},new int[]{R.id.textView1});
        lv.setAdapter(sa);
//        rss.threadRssParse(GpslistActivity.this, sa, list_board, "http://220.93.212.136/sk/board/rss_school.php?lat=" + lat + "&lng=" + lng);
        rss.threadRssParse(GpslistActivity.this, sa, list_board, "http://220.93.212.136/sk/board/rss_school.php?lat=35.1769049&lng=126.8870081");
     lv.setOnItemClickListener(listener);
 }
 AdapterView.OnItemClickListener listener = new AdapterView.OnItemClickListener() {
  @Override
  public void onItemClick(AdapterView<?> list, View view, int position, long id) {
   
   sel_position = position;
   final HashMap<String, String> temp = (HashMap<String, String>)list_board.get(sel_position);
   
   new AlertDialog.Builder(GpslistActivity.this)
   .setMessage(temp.get("name") + " 가 맞습니까?")
   .setPositiveButton("확인", new DialogInterface.OnClickListener() {
    
    @Override
    public void onClick(DialogInterface dialog, int which) {
     
     Log.e( "데이터", temp.get("num") );
     pref = getSharedPreferences("pref", Activity.MODE_PRIVATE);
     
     long saveTime = pref.getLong("savetime", 0);
     
     //현재 시간을 가져옴
     Date date = new Date();
     long now = date.getTime();
     long h12 = 60*60*12*1000;
     
     if(saveTime == 0)
     {
      Log.e( "시간이없음", "현재시간을 입력함");
      SharedPreferences.Editor editor = pref.edit();
      editor.putString("SchoolNum", listNote.NUM);
      editor.putLong("savetime", now);
      editor.commit();
      
      
     }else{
      Log.e( "시간이 있음", "시간을 검사함" );
      if( (now - saveTime) > h12)
      {
       
       Log.e( "시간이 있음", "12시간이 지났음" );
       SharedPreferences.Editor editor = pref.edit();
       editor.putString("SchoolNum", listNote.NUM);
       editor.putLong("savetime", now);
       editor.commit();
      }else{
       Log.e( "시간이 있음", "12시간이전" );
       
      }
     }
      
     if(type == 0)
     {
      Intent intent = new Intent(GpslistActivity.this, ManuActivity.class);
      intent.putExtra("type", type);
      intent.putExtra("num", Integer.parseInt(temp.get("num")) );
      startActivity(intent);
      finish();
      
     }else if(type == 1)
     {
      exit();
     }
    }
   })
   .setNegativeButton("취소", new DialogInterface.OnClickListener() {
    
    @Override
    public void onClick(DialogInterface dialog, int which) {
     
    }
   }) .show();
  }
 };
 
 private void exit()
 {
  this.finish();
 }
}

 

 

 

 

현재 코드입니다

 

 


 

 .setPositiveButton("확인", new DialogInterface.OnClickListener() {
    
    @Override
    public void onClick(DialogInterface dialog, int which) {
     
     Log.e( "데이터", temp.get("num") );
     pref = getSharedPreferences("pref", Activity.MODE_PRIVATE);
     
     long saveTime = pref.getLong("savetime", 0);
     
     //현재 시간을 가져옴
     Date date = new Date();
     long now = date.getTime();
     long h12 = 60*60*12*1000;
     
     if(saveTime == 0)
     {
      Log.e( "시간이없음", "현재시간을 입력함");
      SharedPreferences.Editor editor = pref.edit();
      editor.putString("SchoolNum", listNote.NUM);
      editor.putLong("savetime", now);
      editor.commit();
      
      
     }else{
      Log.e( "시간이 있음", "시간을 검사함" );
      if( (now - saveTime) > h12)
      {
       
       Log.e( "시간이 있음", "12시간이 지났음" );
       SharedPreferences.Editor editor = pref.edit();
       editor.putString("SchoolNum", listNote.NUM);
       editor.putLong("savetime", now);
       editor.commit();
      }else{
       Log.e( "시간이 있음", "12시간이전" );
       
      }
     }
      
     if(type == 0)
     {
      Intent intent = new Intent(GpslistActivity.this, ManuActivity.class);
      intent.putExtra("type", type);
      intent.putExtra("num", Integer.parseInt(temp.get("num")) );
      startActivity(intent);
      finish();
      
     }else if(type == 1)
     {
      exit();
     }
    }
   })
   .setNegativeButton("취소", new DialogInterface.OnClickListener() {
    
    @Override
    public void onClick(DialogInterface dialog, int which) {
     
    }
   }) .show();
  }
 };
 
 private void exit()
 {
  this.finish();
 }


 

 

우선 설명드리자면

 

어플을 첫실행 하면

 

로딩 - 메인 - 리스트 - 메뉴 이런식으로 순차적으로 엑티비티가 실행됩니다 .

 

그런대 위 코드에서 시간저장 12시간이전 이런식으로있습니다 .

 

제가 코드를 짜고싶은거는

 

12시간이전일때 로딩 - 메뉴로 보여주고싶고

 

12시간이후일때 어플을 첫실행한것처럼 순차적으로 보여주려고하는대

 

코딩을 못하겠습니다 ㅠㅠ

 

도와주세요 ㅠㅠ