[MOD][Xposed] Disable Desk Dock - Xposed Framework Modules

Requires Xposed Framework!
This module disables the desk dock feature on your device.
If anyone's wondering how this is useful, I made it for my Xperia Z1's magnetic cable, Sony sells the cable in a dock, so using the cable by itself puts the device in dock mode, which forces rotation regardless of my choice, and if the cable disconnects while my device is in car mode, it switches off car mode, which is kind of annoying while driving.
Compatibility:
Tested on my Z1, I coded it with 4.2 in mind, may or may not work on 4.1 / 4.3, trying it won't do any harm.
Source:
The mod is open source: https://github.com/MohammadAG/Xposed-Disable-Desk-Dock
You may not publish this on the Play Store or any other market.
Download:
http://dl-count.xposed.info/modules/com.mohammadag.disabledeskdock_v1_8f4e5c.apk
Changelog:
[1.0]
Initial release.
Support development:
If you found this mod useful, consider donating with PayPal.

This finally solved the annoying problem with my GT-P3110 (Galaxy Tab 2 7") with Go Launcher (pro). I use Go Launcher also on my tablet to stay consistent with my Xperia Ray - where it works flawlessly. On the GT-P3110 I have to adjust the environment with "App Settings" to be DPI 240 and font-size = 99% and then Go Launcher can be used perfectly for my taste.
The problem with Go Launcher and the GT-P3110 was that Go Launcher restarted every time I have set the tablet in the original dock or when I put it out of it. So any transition from or to desk-dock mode gave me a break until Go Launcher has reloaded all apps
Reporting the problem to Go Development team (twice actually) has not revealed a solution over months - but your module did it - thanks!

Exactly what I've been looking for!
I ran into the problem of some apps closing down due to dock mode, but this seems to be not a problem anymore.

Tried this on my droid maxx xt1080m. It's still bringing up car dock.
My issue is walking around with my phone stacked on top of my tablet in my hand. I guess I could freeze car mode. Any ideas?

Well this made my day thanks! working for me on omnirom 4.4.4 xperia z c6603

finally find a way to disable the auto rotation! thanks a lot for this

finally the solution. everytime i dock the S4, the currently running app closes and needs to be started again. CM11 btw.

Full Uninstall help
I know by myself it's kind of a stange question but, since I'm facing a very courious issue, I'm here to ask if there's any suggetion on how to full disble and remove this module.
I have the phone going into a sort of bootloop when swithced off (only way to recover is "power + vol up" long press combo).
And this is one of the last modifications I made, plus this happens only when I connect the magnetic cable.
Thank you all for your support.

Mr Mohammad sir. Is there any chance this module could be edited to block the detection of the pins in the USB connector that starts car mode? I have googled and googled and have come to the conclusion that on the M8 and its predecessors have faulty USB ports and are prone to collecting dust and/or just being faulty. It is extremely annoying flipping on and out of car mode when have never used and will never use car mode.

bballer182
bballer182 said:
Mr Mohammad sir. Is there any chance this module could be edited to block the detection of the pins in the USB connector that starts car mode? I have googled and googled and have come to the conclusion that on the M8 and its predecessors have faulty USB ports and are prone to collecting dust and/or just being faulty. It is extremely annoying flipping on and out of car mode when have never used and will never use car mode.
Click to expand...
Click to collapse
bballer182
I have the same issue. I really hope MohammadAG can find a solution for us.

Working for me on Android 4.4.4 stock rom Xperia Z3.
and not working on Android 5.0.2 CM rom.
Is there any solution on Android LL (5.0.2)?
It's very useful tool but it can't run on Lollipop.
Thank you.

Same here, running stock 5.0.2 on D6503 where the module is activaded but dock mode is still active. Please adapt the module for LP
Thanks a lot

The developer doesn't look active on XDA anymore since february. Maybe another developer can look at source and adapt it to lollipop.

jassalmithu said:
The developer doesn't look active on XDA anymore since february. Maybe another developer can look at source and adapt it to lollipop.
Click to expand...
Click to collapse
I also mentioned him on twitter. Still no answer.

I compiled APK for Lollipop, somebody can check? On my Z1 C6903 works fine.

My DisableDock.java:
Code:
package com.mohammadag.disabledeskdock;
import static de.robv.android.xposed.XposedHelpers.findAndHookMethod;
import static de.robv.android.xposed.XposedHelpers.findClass;
import static de.robv.android.xposed.XposedHelpers.getIntField;
import static de.robv.android.xposed.XposedHelpers.setIntField;
import android.app.UiModeManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;
import android.content.IntentFilter;
import android.content.res.Configuration;
import de.robv.android.xposed.IXposedHookLoadPackage;
import de.robv.android.xposed.IXposedHookZygoteInit;
import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XC_MethodReplacement;
import de.robv.android.xposed.XposedBridge;
import de.robv.android.xposed.XposedHelpers;
import de.robv.android.xposed.callbacks.XC_LoadPackage;
public class DisableDock implements IXposedHookLoadPackage {
private UiModeManager mUiModeManager = null;
private boolean mIsInCarMode = false;
public void handleLoadPackage(final XC_LoadPackage.LoadPackageParam lpparam) throws Throwable {
if (!lpparam.packageName.equals("android"))
return;
findAndHookMethod("com.android.server.UiModeManagerService", lpparam.classLoader,
"isDeskDockState", int.class, XC_MethodReplacement.returnConstant(false));
Class<?> DockObserver = findClass("com.android.server.DockObserver", lpparam.classLoader);
XposedBridge.hookAllConstructors(DockObserver, new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
Context context = (Context) XposedHelpers.getObjectField(param.thisObject, "mContext");
mUiModeManager = (UiModeManager) context.getSystemService(Context.UI_MODE_SERVICE);
IntentFilter iF = new IntentFilter();
iF.addAction(UiModeManager.ACTION_ENTER_CAR_MODE);
iF.addAction(UiModeManager.ACTION_EXIT_CAR_MODE);
context.registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (UiModeManager.ACTION_ENTER_CAR_MODE.equals(intent.getAction())) {
mIsInCarMode = true;
} else if (UiModeManager.ACTION_EXIT_CAR_MODE.equals(intent.getAction())) {
mIsInCarMode = false;
}
}
}, iF);
}
});
findAndHookMethod(DockObserver, "handleDockStateChange", new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
int mActualDockState = getIntField(param.thisObject, "mActualDockState");
int mReportedDockState = getIntField(param.thisObject, "mReportedDockState");
int mPreviousDockState = getIntField(param.thisObject, "mPreviousDockState");
int newFakeState = Intent.EXTRA_DOCK_STATE_UNDOCKED;
switch (mActualDockState) {
case Intent.EXTRA_DOCK_STATE_DESK:
case Intent.EXTRA_DOCK_STATE_HE_DESK:
case Intent.EXTRA_DOCK_STATE_LE_DESK:
default:
newFakeState = Intent.EXTRA_DOCK_STATE_UNDOCKED;
break;
case Intent.EXTRA_DOCK_STATE_CAR:
newFakeState = Intent.EXTRA_DOCK_STATE_CAR;
break;
}
if (mUiModeManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_CAR || mIsInCarMode) {
newFakeState = Intent.EXTRA_DOCK_STATE_CAR;
setIntField(param.thisObject, "mActualDockState", newFakeState);
// Prevent sound playback
param.setResult(null);
}
String debugString = String.format("Act: %s Prv: %s Rep: %s Fak: %s Car: %s",
getStringFromDockState(mActualDockState), getStringFromDockState(mPreviousDockState),getStringFromDockState(mReportedDockState),
getStringFromDockState(newFakeState), String.valueOf(mIsInCarMode));
// Toast.makeText( context, debugString, Toast.LENGTH_LONG).show();
XposedBridge.log(debugString);
setIntField(param.thisObject, "mActualDockState", newFakeState);
setIntField(param.thisObject, "mReportedDockState", newFakeState);
}
});
}
private static String getStringFromDockState(int dockState) {
switch (dockState) {
case Intent.EXTRA_DOCK_STATE_DESK:
return "Intent.EXTRA_DOCK_STATE_DESK";
case Intent.EXTRA_DOCK_STATE_HE_DESK:
return "Intent.EXTRA_DOCK_STATE_HE_DESK";
case Intent.EXTRA_DOCK_STATE_LE_DESK:
return "Intent.EXTRA_DOCK_STATE_LE_DESK";
case Intent.EXTRA_DOCK_STATE_CAR:
return "Intent.EXTRA_DOCK_STATE_CAR";
case Intent.EXTRA_DOCK_STATE_UNDOCKED:
default:
return "Intent.EXTRA_DOCK_STATE_UNDOCKED";
}
}
}

NickKarpow said:
I compiled APK for Lollipop, somebody can check? On my Z1 C6903 works fine.
Click to expand...
Click to collapse
Thanks! Working on Z1 C6902 :good:
Can you also do some widgets like RecentCallWidget from KK?

NickKarpow said:
I compiled APK for Lollipop, somebody can check? On my Z1 C6903 works fine.
Click to expand...
Click to collapse
Thanks a lot man. I returned my Xperia Z Ultra and waiting for a Xperia Z3 to be delivered. Will test and let you know then. Cheers.

NickKarpow said:
I compiled APK for Lollipop, somebody can check? On my Z1 C6903 works fine.
Click to expand...
Click to collapse
Unfortunately, it doesn't work on my Z1 Compact D5503. Thanks nonetheless!
EDIT: all good now! For some reason, it installed on my SD card!

NickKarpow said:
I compiled APK for Lollipop, somebody can check? On my Z1 C6903 works fine.
Click to expand...
Click to collapse
It worked for me! Thank you very much!!!

Related

[Q] Convert TimeZone to Text

Im trying to convert the results of timezone to text for use in textView. I am new ro android devloping, so i need some help.
Here is my current code:
Code:
TimeZone tz = TimeZone.getDefault();
TextView tv = new TextView(this);
tv.setText(tz);
but it gives me this error:
Code:
The method setText(CharSequence) in the type TextView is not applicable for the arguments (TimeZone)
.
I understand the error, but I do not know how to convert the Timezone to "Eastern Standard Time" or "Pacific Standard Time" or whatever the case may be.
remember im a noob.. so please make it easy and actually show me the code. (im also new to java)
Try this:
Code:
tv.setText(tz.getDisplayName());
Whenever you are stuck its always worth looking through the android reference for the classes you are working with. You'll almost always find a solution there
http://developer.android.com/reference/java/util/TimeZone.html
that fixed it.. Thank you so much!
Yeah but like i say I'm new at java and android. So i can't understand most of it.
alexander7567 said:
that fixed it.. Thank you so much!
Yeah but like i say I'm new at java and android. So i can't understand most of it.
Click to expand...
Click to collapse
No worries. Just continue making some practice apps. And you'll get better at it!
ok my next question is.. I want this to update every 30 seconds. I thought about using a Thread.sleep(10000);, but i realize this would not work because android would detect it being an infinite loop. So how could I create some kind of a thread i believe its called to poll the timezone every 10 seconds?
Where exactly are you trying to set the text view? Is it in a while loop?
no.. the textview simply shows the timezone. I live on the timezone line and i never know what time it really is.. So i was making a app and soon a widget that shows me what timezone I'm in. It's just a learning app for me.
So i need it to poll the timezone every 30 seconds and update the textview to the current time zone.
btw.. Looked at your app and i think its really neat that you can make a game like that.. Did you have to make all the graphics or what?
I am guessing you are making the text view in the onCreate method.
Do this:
Before your activity's onCreate method, make three class members like so
Code:
private TextView textView;
private TimeZone timeZone;
private Timer timer;
Then in the onCreate method do this:
Code:
timer = new Timer();
textView = new TextView(this);
timeZone = TimeZone.getDefault();
TimerTask timerTask = new TimerTask()
{
@Override
public void run()
{
textView.setText(timeZone.getDisplayName());
}
};
timer.schedule(timerTask, 0, 30000);
Then when you wish to stop the timer do this (in the onDestroy method maybe?)
Code:
timer.cancel();
I hope you are familiar with Java's Anonymous Inner Classes. If not, I'd highly recommend first reading and getting familiar with the various Java features and techniques before continuing Android.
---------- Post added at 02:51 AM ---------- Previous post was at 02:48 AM ----------
Thank you!
Yes I made all the graphics. Except for the coin . That was made by my cousin.
i did what u said, and then i put in textView.setTextColor(929) in the time to test and see if it is actually updating, and i found out it is never running the "task"... Know what could be going on?
Sorry about the old code. I did not test it before posting it.
Anyways I've tested the following code and it works fine for me. The timerTask is called every 30 seconds. You can verify this by looking at LogCat.
Code:
public class TestActivity extends Activity
{
private TimeZone timeZone;
private TextView textView;
private Timer timer;
private Handler handler;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
textView = new TextView(this);
timeZone = TimeZone.getDefault();
timer = new Timer();
handler = new Handler()
{
@Override
public void handleMessage(Message msg)
{
textView.setText(timeZone.getDisplayName());
}
};
TimerTask timerTask = new TimerTask()
{
@Override
public void run()
{
handler.sendEmptyMessage(0);
Log.d("TestActivity", "Timer Task Called");
}
};
timer.schedule(timerTask, 0, 30000);
setContentView(textView);
}
@Override
public void onDestroy()
{
super.onDestroy();
timer.cancel();
}
}
Let me know if this works for you
What you gave me works. Thank you! I have done a lot of googling on that but there is nothing more helpful than a personalized answer.
So i think i have one last question. when you used "setContentView(textView);", it sets the whole screen to that text. And i realize this is a really noob question. But i am also trying to display other things in this app. It hides everything else.
So here is my sad atempt to fix it::
Code:
package com.alexriggs.android.timezoneclock;
import java.util.TimeZone;
import java.util.Timer;
import java.util.TimerTask;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.widget.TextView;
public class TimeZoneClockActivity extends Activity
{
private TimeZone timeZone;
private TextView t;
private Timer timer;
private Handler handler;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
t=new TextView(this);
t=(TextView)findViewById(R.id.textView1);
timeZone = TimeZone.getDefault();
timer = new Timer();
handler = new Handler()
{
@Override
public void handleMessage(Message msg)
{
t.setText(timeZone.getDisplayName());
}
};
TimerTask timerTask = new TimerTask()
{
@Override
public void run()
{
handler.sendEmptyMessage(0);
Log.d("TimeZoneClock", "Timer Task Called");
}
};
timer.schedule(timerTask, 0, 30000);
}
@Override
public void onDestroy()
{
super.onDestroy();
timer.cancel();
}
}
I show no compiler errors, but when i run the app i get a force close. I run it in debug mode and the error is around "t.setText(timeZone.getDisplayName());". I have tried googling but i cant seem to find the answer.
Sorry to keep bugging you, but i learn best by doing and not reading.
are there hardcode in this?
Well when you want to load up a view from an xml file you must do this:
Code:
setContentView(R.layout.main);
Where R.layout.main is the resource id of the xml file you wish to load. Only after that you can get the TextView (or any other component that is a part of that xml) using findViewById. And you don't need to do textView = new TextView(this); cause the TextView is already created when using xml, just grab a reference to it using findViewById.
So your code should look like this:
Code:
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main); // Or whatever your layout xml's name is
t=(TextView)findViewById(R.id.textView1);
timeZone = TimeZone.getDefault();
timer = new Timer();
// The rest remains the same
Try it and let me know.
---------- Post added at 12:18 AM ---------- Previous post was at 12:16 AM ----------
randommmm said:
are there hardcode in this?
Click to expand...
Click to collapse
Sorry, but I'm not sure I understand what you mean to ask.
wow.. That was so simple i now feel stupid lol.
Yes that fixed it. Thank you so much for your help.
Ok.. new question for that same program.. I am now attempting to create a widget for this that simply displays a text view that shows the timezone. My problem is it simply show 'Large Text". It is not updating the text view to the timezone. Here is my code in AppWidget.java.
Code:
package com.alexriggs.android.timezoneclock;
import java.util.TimeZone;
import java.util.Timer;
import java.util.TimerTask;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.widget.TextView;
public class AppWidget extends AppWidgetProvider {
private TimeZone timeZone;
private TextView t;
private Timer timer;
private Handler handler;
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
t=new TextView(context);
timeZone = TimeZone.getDefault();
timer = new Timer();
handler = new Handler()
{
@Override
public void handleMessage(Message msg)
{
t.setText(timeZone.getDisplayName());
}
};
TimerTask timerTask = new TimerTask()
{
@Override
public void run()
{
handler.sendEmptyMessage(0);
Log.d("TestActivity", "Timer Task Called");
}
};
timer.schedule(timerTask, 0, 30000);
}
}
BTW... Seems like this is the hardest language I have ever tried to learn.
I realize im missing setContentView(R.layout.widget), but everytime i set it i get "The method setContentView(int) is undefined for the type AppWidget". Could that be thte issue?
Hello again
I'm not really familiar with making widgets myself, so I cannot really say what you are doing wrong. I found a link to this tutorial on making a simple widget. I think you should try and follow it and see if you can get something out of it.
Let me know if it is helpful for you or not
http://www.vogella.com/articles/AndroidWidgets/article.html
It was a lot more helpful than most things out there.
But i still am not able to understand it the best.
What i am wanting to accomplish is simply make a text view widget that displays the timezone (I.E. EST, CST, PST) and make it refresh every 30 seconds.
It isn't very hard to do in a normal app, but a widget seems impossible to me.
Is there anyone that can help me with This?

[Q] OnClickListener vs. android:OnClick

I'm looking at both a book and the beginning projects on developers.android.com and have a question. Google is utilizing the android:nClick to handle the click event which then points to a public method for execution....but the book is setting up click listeners by setting a View with the buttons ID and then executing the setOnClickListener. OnClickListenver has one method called OnClick which is then executed.
//book
public class MyGame extends Activity implements OnClickListener {
View continueButton = findViewById(R.id.continue_button);
continueButton.setOnClickListener(this);
View newButton = findViewById(R.id.new_button);
newButton.setOnClickListener(this);
View aboutButton = findViewById(R.id.about_button);
aboutButton.setOnClickListener(this);
View exitButton = findViewById(R.id.exit_button);
exitButton.setOnClickListener(this);
}
public void onClick(View v) {
switch (v.getId()) {
case R.id.about_button:
Intent i = new Intent(this, About.class);
startActivity(i);
break;
}
}
My question. Which is the better way to handle the Button Click? In looking at what google does in the XML, it seems a helluva lot cleaner....but curious on what the advantage is for the other way (and I cannot think of any). Search of the site didn't yield anything.
I dunno if the methods have advantages between them, however, I prefer the androidnClick method since the code looks clearer
You usually want to use the onClick method, as there is no benefit to implementing the OnClickListener (only more effort and possible performance loss).
If you want things like long clicks or other events, you will have to implement that (or define an inline listener), as there is no xml tag for those.
I think the OnClickListener is actually only there for consistency with these other classes

[GUIDE] Customizing Sony W. Button behaviour

I recently got an SONY NWZ-F806 Walkman with Android. I bought it to listen to Spotify and everything works fine but the fact that you cannot control Spotify with the the dedicated W. button on the side of the device.
So I googled and found a solution where you had to redirect the W. button to the search button which was not satisfying to me. So I decided to investigate deeper into this and with a little help of adb and dumpsys I found the Intent that was fired when the W. button is pressed "com.sony.walkman.intent.action.WALKMAN_BUTTON". Than I found the service which was responsible for the default behavior "W.control".
So to redirect the W. button to Spotify I had to do the following things:
1) Disable the default W. behavior
To do this you simply have to deactivate the W.control service
Systemsettings > Apps > All > W.control > Disable
2) To listen to the W. button a BroadcastReceiver has to be implemented which receives to the Intent "com.sony.walkman.intent.action.WALKMAN_BUTTON" and sends a Intent to Spotify
AndroidManifest.xml
Code:
<application>
<receiver android:name=".WDotReceiver" >
<intent-filter>
<action android:name="com.sony.walkman.intent.action.WALKMAN_BUTTON" />
</intent-filter>
</receiver>
</application>
WDotReceiver.java
Code:
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
public class WDotReceiver extends BroadcastReceiver {
private static final String KEY_EVENT_KEY = "android.intent.extra.KEY_EVENT";
private static final String SPOTIFY_PLAY_KEY = "com.spotify.mobile.android.ui.widget.PLAY";
private static final String SPOTIFY_NEXT_KEY = "com.spotify.mobile.android.ui.widget.NEXT";
@Override
public void onReceive(Context arg0, Intent arg1) {
Bundle extrasBundle = arg1.getExtras();
if(extrasBundle != null)
{
if(extrasBundle.containsKey(KEY_EVENT_KEY))
{
KeyEvent keyEvent = extrasBundle.getParcelable(KEY_EVENT_KEY);
if(keyEvent.getAction() == KeyEvent.ACTION_DOWN && keyEvent.getRepeatCount() == 0)
{
arg0.sendBroadcast(new Intent(SPOTIFY_PLAY_KEY));
}
else if(keyEvent.getAction() == KeyEvent.ACTION_DOWN && keyEvent.getRepeatCount() == 1)
{
arg0.sendBroadcast(new Intent(SPOTIFY_NEXT_KEY));
}
}
}
}
}
If you press the W. button for a short time a Play/Pause Intent is send and if you press the button longer Spotify will skip to the next track.
To me this increases the usability of the device tremendously.
Kind regards
Mathias
wrong forum bro

Need help with voice recognition application dev

I'm developing an augmentative communication application for use on Kindle Fire. I'm using Fire HD 6 as my test device. I'm working in Xamarin, C#.
I know there is a speech recognizer on the device as the microphone icon appears on the keyboard and I can use it to populate the search window. However, my andoid speech recognizer code is not working. I get the "recognizer not present" error. Here is the code that I'm working with:
public class VoiceRecognition : Activity
{
private static String TAG = "VoiceRecognition";
private const int VOICE_RECOGNITION_REQUEST_CODE = 1234;
private ListView mList;
public Handler mHandler;
private Spinner mSupportedLanguageView;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
mHandler = new Handler();
SetContentView(Resource.Layout.Main);
Button speakButton = FindViewById<Button>(Resource.Id.btnRecord);
// Check to see if a recognition activity is present
PackageManager pm = PackageManager;
IList<ResolveInfo> activities = pm.QueryIntentActivities(new Intent(RecognizerIntent.ActionRecognizeSpeech), 0);
if (activities.Count != 0)
speakButton.Click += speakButton_Click;
else
{
speakButton.Enabled = false;
speakButton.Text = "Recognizer not present";
}
}
Click to expand...
Click to collapse
This code is obviously not going to work, but I don't know where to go from here. How can I access the voice recognizer on this device?
Thanks!

Google Maps Android changing markers.

Hello! I am working on a Google Maps Android API project and am having a difficult time. I have several markers on my map, which is an indoor location. I was able to change the color of the markers, but would like to change the icons as well. I've looked over the documentation from google and am trying to implement it but it is not working and I cannot go any further until it does. Id like to use custom images, but for now I want to just see it work. Im trying to use this code:
Code:
.icon(BitmapDescriptorFactory.fromResource(R.drawable.arrow))
. I'm getting an error in Android studio saying that it can't resolve 'arrow' symbol. my full code is here: It doesn't seem like I'm missing any imports, so I'm not sure why this doesn't work.
Code:
package com.aa.maps;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import com.google.android.gms.maps.model.BitmapDescriptor;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {
private GoogleMap mMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
public Bitmap resizeMapIcons(String iconName, int width, int height){
Bitmap imageBitmap = BitmapFactory.decodeResource(getResources(),getResources().getIdentifier(iconName, "drawable", getPackageName()));
Bitmap resizedBitmap = Bitmap.createScaledBitmap(imageBitmap, width, height, false);
return resizedBitmap;
}
/**
* Manipulates the map once available.
* This callback is triggered when the map is ready to be used.
* This is where we can add markers or lines, add listeners or move the camera. In this case,
* we just add a marker near Milwaukee, Wisconsin.
* If Google Play services is not installed on the device, the user will be prompted to install
* it inside the SupportMapFragment. This method will only be triggered once the user has
* installed Google Play services and returned to the app.
*/
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
mMap.getUiSettings().setZoomControlsEnabled(true);
mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
// Add a marker in Milwaukee and move the camera
LatLng mpm = new LatLng(43.0408468, -87.921474);
LatLng planetarium = new LatLng(43.040622, -87.920798);
LatLng theater = new LatLng(43.040497, -87.920640);
LatLng marketplace = new LatLng(43.040779, -87.921717);
mMap.addMarker(new MarkerOptions().position(mpm).title("Milwaukee Public Museum").icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_ORANGE))).showInfoWindow();
mMap.addMarker(new MarkerOptions().position(planetarium).title("The Daniel M. Soref National Geographic Planetarium").icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE)));
mMap.addMarker(new MarkerOptions().position(theater).title("The Daniel M. Soref National Geographic Theater").icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN)));
mMap.addMarker(new MarkerOptions().position(marketplace).title("Museum Marketplace"));
mMap.addMarker(new MarkerOptions().position(marketplace).title("Museum Marketplace").icon(BitmapDescriptorFactory.fromResource(R.drawable.arrow)));
}
}

Categories

Resources