Home | History | Annotate | Download | only in systemupdater
      1 /*
      2  * Copyright (C) 2015 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 package com.android.car.systemupdater;
     17 
     18 import android.app.Fragment;
     19 import android.os.Bundle;
     20 import android.view.LayoutInflater;
     21 import android.view.View;
     22 import android.view.ViewGroup;
     23 import android.widget.AdapterView;
     24 import android.widget.Button;
     25 import android.widget.ListView;
     26 import android.widget.TextView;
     27 import android.widget.Toast;
     28 
     29 import java.io.File;
     30 
     31 public class DeviceListFragment extends Fragment {
     32     private ListView mFolderListView;
     33     private SystemUpdaterActivity mActivity;
     34     private File[] mFileNames = new File[0];
     35     private FileAdapter mAdapter;
     36     private Button mBackButton;
     37     private TextView mTitle;
     38     private String mTitleText;
     39 
     40     @Override
     41     public void onCreate(Bundle savedInstanceState) {
     42         super.onCreate(savedInstanceState);
     43         mActivity = (SystemUpdaterActivity) getActivity();
     44         mAdapter = new FileAdapter(mActivity, R.layout.folder_entry, mFileNames);
     45     }
     46     @Override
     47     public View onCreateView(LayoutInflater inflater, final ViewGroup container,
     48                              Bundle savedInstanceState) {
     49         View v = inflater.inflate(R.layout.folder_list, container, false);
     50         mTitle = (TextView) v.findViewById(R.id.title);
     51         if (mTitleText != null) {
     52             mTitle.setText(mTitleText);
     53         }
     54         mFolderListView = (ListView) v.findViewById(R.id.folder_list);
     55         mFolderListView.setAdapter(mAdapter);
     56         mFolderListView.setOnItemClickListener(mItemClickListener);
     57         mBackButton = (Button) v.findViewById(R.id.back);
     58         mBackButton.setOnClickListener(mBackButtonListener);
     59         return v;
     60     }
     61 
     62     public void updateList(File[] locations) {
     63         if (locations != null) {
     64             mFileNames = locations;
     65             if (mAdapter != null) {
     66                 mAdapter.setLocations(mFileNames);
     67             }
     68         }
     69     }
     70 
     71     public void updateTitle(String title) {
     72         if (mTitle != null) {
     73             mTitle.setText(title);
     74         } else {
     75             mTitleText = title;
     76         }
     77     }
     78 
     79     private final View.OnClickListener mBackButtonListener =
     80             new View.OnClickListener() {
     81                 @Override
     82                 public void onClick(View view) {
     83                     mActivity.onBackPressed();
     84                 }
     85             };
     86 
     87     private final AdapterView.OnItemClickListener mItemClickListener =
     88             new AdapterView.OnItemClickListener() {
     89                 @Override
     90                 public void onItemClick(AdapterView<?> adapterView, View view,
     91                                         int position, long id) {
     92                     if (mFileNames[position].getName().endsWith(".zip")) {
     93                         mActivity.checkPackage(mFileNames[position]);
     94                     } else if (mFileNames[position].isDirectory()) {
     95                         mActivity.showFolderContent(mFileNames[position]);
     96                     } else {
     97                         Toast.makeText(mActivity, "This is not a valid file for updating",
     98                                 Toast.LENGTH_LONG).show();
     99                     }
    100                 }
    101             };
    102 }
    103