Home | History | Annotate | Download | only in presets
      1 /*
      2  * Copyright (C) 2013 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 
     17 package com.android.gallery3d.filtershow.presets;
     18 
     19 import android.os.Bundle;
     20 import android.support.v4.app.DialogFragment;
     21 import android.view.LayoutInflater;
     22 import android.view.View;
     23 import android.view.ViewGroup;
     24 import android.widget.EditText;
     25 import android.widget.ImageView;
     26 import android.widget.ListView;
     27 import com.android.gallery3d.R;
     28 import com.android.gallery3d.filtershow.FilterShowActivity;
     29 
     30 public class PresetManagementDialog extends DialogFragment implements View.OnClickListener {
     31     private UserPresetsAdapter mAdapter;
     32     private EditText mEditText;
     33 
     34     @Override
     35     public View onCreateView(LayoutInflater inflater, ViewGroup container,
     36                              Bundle savedInstanceState) {
     37         View view = inflater.inflate(R.layout.filtershow_presets_management_dialog, container);
     38 
     39         FilterShowActivity activity = (FilterShowActivity) getActivity();
     40         mAdapter = activity.getUserPresetsAdapter();
     41         mEditText = (EditText) view.findViewById(R.id.editView);
     42         view.findViewById(R.id.cancel).setOnClickListener(this);
     43         view.findViewById(R.id.ok).setOnClickListener(this);
     44         getDialog().setTitle(getString(R.string.filtershow_save_preset));
     45         return view;
     46     }
     47 
     48     @Override
     49     public void onClick(View v) {
     50         FilterShowActivity activity = (FilterShowActivity) getActivity();
     51         switch (v.getId()) {
     52             case R.id.cancel:
     53                 mAdapter.clearChangedRepresentations();
     54                 mAdapter.clearDeletedRepresentations();
     55                 activity.updateUserPresetsFromAdapter(mAdapter);
     56                 dismiss();
     57                 break;
     58             case R.id.ok:
     59                 String text = String.valueOf(mEditText.getText());
     60                 activity.saveCurrentImagePreset(text);
     61                 mAdapter.updateCurrent();
     62                 activity.updateUserPresetsFromAdapter(mAdapter);
     63                 dismiss();
     64                 break;
     65         }
     66     }
     67 }
     68