Home | History | Annotate | Download | only in fontlab
      1 /*
      2  * Copyright (C) 2007 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.fontlab;
     18 
     19 import java.util.ArrayList;
     20 import java.util.List;
     21 
     22 import android.app.ListActivity;
     23 import android.content.Intent;
     24 import android.graphics.Typeface;
     25 import android.os.Bundle;
     26 import android.view.View;
     27 import android.widget.ListView;
     28 import android.widget.SimpleAdapter;
     29 
     30 
     31 public abstract class FontPicker extends ListActivity
     32 {
     33 
     34     public void onCreate(Bundle icicle)
     35     {
     36         super.onCreate(icicle);
     37 
     38         setListAdapter(new SimpleAdapter(this,
     39                 getData(),
     40                 android.R.layout.simple_list_item_1,
     41                 new String[] {"title"},
     42                 new int[] {android.R.id.text1}));
     43     }
     44 
     45     protected List getData()
     46     {
     47         List myData = new ArrayList<Bundle>(7);
     48         addItem(myData, "Sans",                 "sans-serif",   Typeface.NORMAL);
     49         addItem(myData, "Sans Bold",            "sans-serif",   Typeface.BOLD);
     50         addItem(myData, "Serif",                "serif",        Typeface.NORMAL);
     51         addItem(myData, "Serif Bold",           "serif",        Typeface.BOLD);
     52         addItem(myData, "Serif Italic",         "serif",        Typeface.ITALIC);
     53         addItem(myData, "Serif Bold Italic",    "serif",        Typeface.BOLD_ITALIC);
     54         addItem(myData, "Mono",                 "monospace",    Typeface.NORMAL);
     55         return myData;
     56     }
     57 
     58     protected void addItem(List<Bundle> data, String name, String fontName, int style)
     59     {
     60         Bundle temp = new Bundle();
     61         temp.putString("title", name);
     62         temp.putString("font", fontName);
     63         temp.putInt("style", style);
     64         data.add(temp);
     65     }
     66 
     67     protected void onListItemClick(ListView l, View v, int position, long id)
     68     {
     69         Bundle map = (Bundle) l.getItemAtPosition(position);
     70         setResult(RESULT_OK, (new Intent()).putExtras(map));
     71         finish();
     72     }
     73 
     74 }
     75