2011-08-10 24 views
0

我想使我的佈局不可調焦即:我希望用戶無法單擊佈局上的按鈕,直到解析完成 我已經做了使按鈕無法點擊並且可點擊時解析完成我想使我的佈局不可調焦

,但如果我可以讓

protected void onCreate(Bundle savedInstanceState) 
{ 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

    progress_waiting1=(ProgressBar)findViewById(R.id.progress1); 
    progress_waiting1.setVisibility(ProgressBar.VISIBLE); 


    progress_waiting2=(ProgressBar)findViewById(R.id.progress2); 
    progress_waiting2.setVisibility(ProgressBar.VISIBLE); 

    Typeface tf_helvetica = Typeface.createFromAsset(getAssets(),"fonts/HelveticaNw.ttf"); 
    Typeface tf_helvetica_bold = Typeface.createFromAsset(getAssets(),"fonts/HelveticaNwBd.ttf"); 

    Config.TF_HELVETICA=tf_helvetica; 
    Config.TF_HELVETICA_BOLD=tf_helvetica_bold; 



    bttn_bedpress=(ImageButton)findViewById(R.id.bttn_bedpress); 
    bttn_news=(ImageButton)findViewById(R.id.bttn_news); 
    bttn_logo=(ImageButton)findViewById(R.id.bttn_logo); 
    bttn_faq=(ImageButton)findViewById(R.id.bttn_faq); 
    bttn_cv=(ImageButton)findViewById(R.id.bttn_cv); 
    bttn_omnu=(ImageButton)findViewById(R.id.bttn_omnu); 

    bttn_recent=(ImageButton)findViewById(R.id.button1); 

    bttn_bedpress.setClickable(false); 
    bttn_news.setClickable(false); 
    bttn_logo.setClickable(false); 
    bttn_faq.setClickable(false); 
    bttn_cv.setClickable(false); 
    bttn_omnu.setClickable(false); 

    bttn_recent.setClickable(false); 

    img_gray_bg=(RelativeLayout)findViewById(R.id.img_gray_bg); 
    img_gray_bg.setVisibility(ImageView.VISIBLE); 

    txt_wait=(TextView)findViewById(R.id.txt_wait); 
    txt_wait.setVisibility(TextView.VISIBLE); 
    txt_wait.setTypeface(Config.TF_HELVETICA_BOLD); 

    topheading=(TextView)findViewById(R.id.txt_topheading); 
     topheading.setTypeface(Config.TF_HELVETICA_BOLD); 
    headline=(TextView)findViewById(R.id.txt_headline); 
     headline.setTypeface(Config.TF_HELVETICA_BOLD); 
    date=(TextView)findViewById(R.id.txt_date); 
     date.setTypeface(Config.TF_HELVETICA_BOLD); 
    txt_place=(TextView)findViewById(R.id.txt_place); 
     txt_place.setTypeface(Config.TF_HELVETICA_BOLD); 
    img_company=(ImageView)findViewById(R.id.img_company); 

    txt_news=(TextView)findViewById(R.id.txt_news); 
     txt_news.setTypeface(Config.TF_HELVETICA_BOLD); 
    txt_career=(TextView)findViewById(R.id.txt_career); 
     txt_career.setTypeface(Config.TF_HELVETICA_BOLD); 
    txt_bedpress=(TextView)findViewById(R.id.txt_bedpress); 
     txt_bedpress.setTypeface(Config.TF_HELVETICA_BOLD); 

    txt_cv=(TextView)findViewById(R.id.txt_cv); 
     txt_cv.setTypeface(Config.TF_HELVETICA_BOLD); 
    txt_faq=(TextView)findViewById(R.id.txt_faq); 
     txt_faq.setTypeface(Config.TF_HELVETICA_BOLD); 
    txt_logo=(TextView)findViewById(R.id.txt_logo); 
     txt_logo.setTypeface(Config.TF_HELVETICA_BOLD); 

     doAction(); 
} 

public void doAction() 
{ 
    progress_waiting1.setVisibility(ProgressBar.VISIBLE); 

    progress_waiting2.setVisibility(ProgressBar.VISIBLE); 

    img_gray_bg.setVisibility(ImageView.VISIBLE); 

    txt_wait.setVisibility(TextView.VISIBLE); 

     topheading.setTypeface(Config.TF_HELVETICA_BOLD); 
     headline.setTypeface(Config.TF_HELVETICA_BOLD); 
     date.setTypeface(Config.TF_HELVETICA_BOLD); 
     txt_place.setTypeface(Config.TF_HELVETICA_BOLD); 


     txt_news.setTypeface(Config.TF_HELVETICA_BOLD); 

     txt_career.setTypeface(Config.TF_HELVETICA_BOLD); 

     txt_bedpress.setTypeface(Config.TF_HELVETICA_BOLD); 


     txt_cv.setTypeface(Config.TF_HELVETICA_BOLD); 

     txt_faq.setTypeface(Config.TF_HELVETICA_BOLD); 

     txt_logo.setTypeface(Config.TF_HELVETICA_BOLD); 

    if(!HaveNetworkConnection()) 
    { 
     AlertDialog.Builder builder = new AlertDialog.Builder(this); 
     builder.setMessage("Nettverk ikke tilgjengelig") 
       .setCancelable(false) 
       .setPositiveButton("Ok", new DialogInterface.OnClickListener() { 
        public void onClick(DialogInterface dialog, int id) 
        { 
         dialog.cancel(); 
        } 
       }); 

     AlertDialog alert = builder.create(); 
     alert.show(); 
    } 

    final Thread parseThread=new Thread(new Runnable() { 

     public void run() 
     { 
      if(HaveNetworkConnection()) 
      { 
       parseDataBedPres(Config.URL_BedPres); 
       parseDataNyheter(Config.URL_Nyheter); 
       Collections.sort(mydate); 

      } 
      else 
      { 
       parseDataBedPresLocal(); 
       parseDataNyheterLocal(); 
      } 
     } 
    }); 
    parseThread.start(); 

    Thread displayThread = new Thread(new Runnable() { 
     public void run() { 

     try 
     { 
      parseThread.join(); 
     } 
     catch (InterruptedException e) 
     { 
      e.printStackTrace(); 
     } 
     mHandler.post(new Runnable() { 
      public void run() 
      { 

       progress_waiting1.setVisibility(ProgressBar.GONE); 
       progress_waiting2.setVisibility(ProgressBar.GONE); 
       txt_wait.setVisibility(TextView.GONE); 
       img_gray_bg.setVisibility(ImageView.GONE); 



       String month[]=getResources().getStringArray(R.array.month_array); 

       if(data_bedpres_future.size()!=0) 
       { 
        int pos=data_bedpres_future.get(0).size()-1; 
        DateFormat df=new SimpleDateFormat("yyyy-MM-dd"); 
        Date dt = null; 
        Calendar cal = Calendar.getInstance(); 
        try 
        { 
         dt = df.parse(data_bedpres_future.get(1).get(pos)); 
         cal.setTime(dt); 
        } 
        catch (ParseException e1) 
        { 
         e1.printStackTrace(); 
        } 

        DateFormat df2=new SimpleDateFormat("hh:mm:ss"); 
        Date dt2 = null; 
        Calendar cal2 = Calendar.getInstance(); 
        try 
        { 
         dt2 = df2.parse(data_bedpres_future.get(2).get(pos)); 
         cal2.setTime(dt2); 
        } 
        catch (ParseException e1) 
        { 
         e1.printStackTrace(); 
        } 



        date.setText("Tid: "+cal.get(Calendar.DATE)+" "+month[cal.get(Calendar.MONTH)]+" kl "+cal2.get(Calendar.HOUR_OF_DAY)+":"+cal2.get(Calendar.MINUTE)); 

        //date.setText("Tid : "+data_bedpres_future.get(1).get(0)); 
        headline.setText("Neste Bed.pres: "+data_bedpres_future.get(0).get(pos)); 
        txt_place.setText("Sted: "+data_bedpres_future.get(3).get(pos)); 
        try 
        { 

          Drawable img = drawable_from_url(data_bedpres_future.get(4).get(pos),"icon"); 
          if(img!=null) 
          { 
           int height,width,w; 
           height = img.getMinimumHeight() > 52 ? 52 :img.getMinimumHeight(); 
           int ratio = (((img.getMinimumHeight() - height)*100)/img.getMinimumHeight()); 
           int wi = (img.getMinimumWidth() * ratio) /100; 
           width = img.getMinimumWidth() -wi; 
           w=width; 
           int width1 = width > 211 ? 211 :width; 
           if (width>0) 
           { 
            ratio = (((width - width1)*100)/width); 
            int hi = (height * ratio) /100; 
            height = height -hi; 
            w=width1; 
           } 

           ViewGroup.LayoutParams params = img_company.getLayoutParams(); 
           params.height = height; 
           params.width = w; 
           img_company.setLayoutParams(params); 
           img_company.setBackgroundDrawable(drawable_from_url(data_bedpres_future.get(4).get(pos),"icon")); 
          } 

        } catch (MalformedURLException e) 
        { 
         e.printStackTrace(); 
        } catch (IOException e) 
        { 
         e.printStackTrace(); 
        } 
       } 
       else if(data_nyheter_future.size()!=0) 
       { 
        date.setText(data_nyheter_future.get(2).get(0)); 
        headline.setText("Siste nyhet: "+data_nyheter_future.get(3).get(0));  


        try 
        { 
         Drawable img = drawable_from_url(data_nyheter_future.get(0).get(0),"icon"); 
         if(img!=null) 
         { 
          int height,width,w; 
          height = img.getMinimumHeight() > 52 ? 52 :img.getMinimumHeight(); 
          int ratio = (((img.getMinimumHeight() - height)*100)/img.getMinimumHeight()); 
          int wi = (img.getMinimumWidth() * ratio) /100; 
          width = img.getMinimumWidth() -wi; 
          w=width; 
          int width1 = width > 211 ? 211 :width; 
          if (width>0) 
          { 
           ratio = (((width - width1)*100)/width); 
           int hi = (height * ratio) /100; 
           height = height -hi; 
           w=width1; 
          } 

          ViewGroup.LayoutParams params = img_company.getLayoutParams(); 
          params.height = height; 
          params.width = w; 
          img_company.setLayoutParams(params); 
         img_company.setBackgroundDrawable(img); 
        } 
        }catch (MalformedURLException e) 
        { 
         e.printStackTrace(); 
        } catch (IOException e) 
        { 
         e.printStackTrace(); 
        } 
       } 
       else if(data_nyheter_past.size()!=0) 
       { 
        DateFormat df=new SimpleDateFormat("yyyy-MM-dd"); 
        Date dt = null; 
        Calendar cal = Calendar.getInstance(); 
        try 
        { 
         dt = df.parse(data_nyheter_past.get(2).get(0)); 
         cal.setTime(dt); 
        } 
        catch (ParseException e1) 
        { 
         e1.printStackTrace(); 
        } 
        date.setText("Dato: "+cal.get(Calendar.DATE)+"."+(cal.get(Calendar.MONTH)+1)+"."+cal.get(Calendar.YEAR)); 
        headline.setText("Siste nyhet: "+data_nyheter_past.get(3).get(0)); 

        try 
        { 
         Drawable img = drawable_from_url(data_nyheter_past.get(0).get(0),"icon"); 
         if(img!=null) 
         { 
          int height,width,w; 
          height = img.getMinimumHeight() > 52 ? 52 :img.getMinimumHeight(); 
          int ratio = (((img.getMinimumHeight() - height)*100)/img.getMinimumHeight()); 
          int wi = (img.getMinimumWidth() * ratio) /100; 
          width = img.getMinimumWidth() -wi; 
          w=width; 
          int width1 = width > 211 ? 211 :width; 
          if (width>0) 
          { 
           ratio = (((width - width1)*100)/width); 
           int hi = (height * ratio) /100; 
           height = height -hi; 
           w=width1; 
          } 

          ViewGroup.LayoutParams params = img_company.getLayoutParams(); 
          params.height = height; 
          params.width = w; 
          img_company.setLayoutParams(params); 
         img_company.setBackgroundDrawable(img); 
        } 
        } 
        catch (MalformedURLException e) 
        { 
         e.printStackTrace(); 
        } catch (IOException e) 
        { 
         e.printStackTrace(); 
        } 
       } 

       bttn_bedpress.setClickable(true); 
       bttn_news.setClickable(true); 
       bttn_logo.setClickable(true); 
       bttn_faq.setClickable(true); 
       bttn_cv.setClickable(true); 
       bttn_omnu.setClickable(true); 

       bttn_recent.setClickable(true); 
      } 
     }); 

     } 
    }); 
    displayThread.start(); 
+1

您應該刪除不重要的代碼。只是一個提示,下次... – WarrenFaith

回答

相關問題