Show dialog and parse URL
/*
* Copyright 2011 Atos Wordline
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
//package com.awl.tumlabs.twitter.android;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLDecoder;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.os.Bundle;
class Util {
protected static Bundle parseUrl(String url, String protocol) {
url = url.replace(protocol, "http://");
try {
URL u = new URL(url);
Bundle b = decodeUrl(u.getQuery());
b.putAll(decodeUrl(u.getRef()));
return b;
} catch (MalformedURLException e) {
return new Bundle();
}
}
protected static Bundle decodeUrl(String s) {
Bundle params = new Bundle();
if (s != null) {
String array[] = s.split("&");
for (String parameter : array) {
String v[] = parameter.split("=");
params.putString(URLDecoder.decode(v[0]),
URLDecoder.decode(v[1]));
}
}
return params;
}
protected static void showAlert(Context context, String title, String text) {
Builder alertBuilder = new Builder(context);
alertBuilder.setTitle(title);
alertBuilder.setMessage(text);
alertBuilder.create().show();
}
}
Related examples in the same category