/[zanavi_public1]/navit/navit/android/src/com/zoffcc/applications/zanavi/NavitDeleteSelectMapActivity.java
ZANavi

Contents of /navit/navit/android/src/com/zoffcc/applications/zanavi/NavitDeleteSelectMapActivity.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 41 - (show annotations) (download)
Tue Aug 11 18:50:37 2015 UTC (8 years, 7 months ago) by zoff99
File size: 3983 byte(s)
many fixes, and new features
1 /**
2 * ZANavi, Zoff Android Navigation system.
3 * Copyright (C) 2011 Zoff <zoff@zoff.cc>
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * version 2 as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
20 package com.zoffcc.applications.zanavi;
21
22 import android.app.Activity;
23 import android.app.ListActivity;
24 import android.content.Intent;
25 import android.os.Build;
26 import android.os.Bundle;
27 import android.support.v7.widget.Toolbar;
28 import android.support.v7.widget.Toolbar.LayoutParams;
29 import android.view.LayoutInflater;
30 import android.view.View;
31 import android.view.ViewGroup;
32 import android.widget.ArrayAdapter;
33 import android.widget.LinearLayout;
34 import android.widget.ListView;
35
36 public class NavitDeleteSelectMapActivity extends ListActivity
37 {
38 private int selected_id = -1;
39 private int my_id = 0;
40
41 protected void onPostCreate(Bundle savedInstanceState)
42 {
43 super.onPostCreate(savedInstanceState);
44 Toolbar bar;
45
46 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH)
47 {
48 ViewGroup root_view = (ViewGroup) findViewById(my_id).getParent().getParent();
49
50 bar = (Toolbar) LayoutInflater.from(this).inflate(R.layout.settings_toolbar, root_view, false);
51 bar.setTitle(Navit.get_text("delete maps"));
52 root_view.addView(bar, 0); // insert at top
53 }
54 else
55 {
56 ViewGroup root_view = (ViewGroup) findViewById(android.R.id.content);
57 ListView content = (ListView) root_view.getChildAt(0);
58
59 root_view.removeAllViews();
60
61 LinearLayout ll = new LinearLayout(this);
62 ll.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
63 ll.setOrientation(LinearLayout.VERTICAL);
64
65 bar = (Toolbar) LayoutInflater.from(this).inflate(R.layout.settings_toolbar, root_view, false);
66 bar.setTitle(Navit.get_text("delete maps"));
67 root_view.addView(ll);
68
69 // int height;
70 // TypedValue tv = new TypedValue();
71 // if (getTheme().resolveAttribute(R.attr.actionBarSize, tv, true))
72 // {
73 // height = TypedValue.complexToDimensionPixelSize(tv.data, getResources().getDisplayMetrics());
74 // }
75 // else
76 // {
77 // height = bar.getHeight();
78 // }
79 //
80 // content.setPadding(0, height, 0, 0);
81
82 ll.addView(bar);
83 ll.addView(content);
84 }
85
86 bar.setNavigationOnClickListener(new View.OnClickListener()
87 {
88 @Override
89 public void onClick(View v)
90 {
91 finish();
92 }
93 });
94 }
95
96 @Override
97 public void onCreate(Bundle savedInstanceState)
98 {
99 Navit.applySharedTheme(this, Navit.p.PREF_current_theme);
100
101 super.onCreate(savedInstanceState);
102
103 NavitMapDownloader.init_ondisk_maps();
104 ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, NavitMapDownloader.OSM_MAP_NAME_LIST_ondisk);
105 setListAdapter(adapter);
106 this.getListView().setFastScrollEnabled(true);
107 my_id = this.getListView().getId();
108 }
109
110 @Override
111 protected void onListItemClick(ListView l, View v, int position, long id)
112 {
113 super.onListItemClick(l, v, position, id);
114 // Get the item that was clicked
115 this.selected_id = position;
116 // close this activity
117 executeDone();
118 }
119
120 private void executeDone()
121 {
122 Intent resultIntent = new Intent();
123 resultIntent.putExtra("selected_id", String.valueOf(this.selected_id));
124 setResult(Activity.RESULT_OK, resultIntent);
125 finish();
126 }
127 }

   
Visit the ZANavi Wiki