[Q] [HELP] resize gridview - Windows Phone 8 Q&A, Help & Troubleshooting

Hi,
I have a grid view with ítems that have a constant size and I want to change the margin between ítems in order to fill all area. So I Put a staticresource on page and this is changed from the event but it doesn't work. I have attached the code.
XAML
Code:
<Page.Resources>
<!-- Colección de elementos que muestra esta página -->
<CollectionViewSource
x:Name="itemsViewSource"
Source="{Binding Items}"/>
<Thickness x:Key="margenGrid" >10</Thickness>
</Page.Resources>
##......##
<GridView
x:Name="itemGridView"
AutomationProperties.AutomationId="ItemGridView"
AutomationProperties.Name="Items In Group"
TabIndex="1"
Grid.RowSpan="2"
ItemsSource="{Binding Source={StaticResource itemsViewSource}}"
SelectionMode="Multiple"
CanDragItems="True"
AllowDrop="True"
SizeChanged="itemGridView_SizeChanged"
CanReorderItems="True">
<GridView.ItemTemplate>
<DataTemplate>
<Grid Height="80" Width="200" Margin="{StaticResource margenGrid}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Border Background="{ThemeResource ComboBoxSelectedBackgroundThemeBrush}" Width="80" Height="80">
<Image Source="{Binding Imagen}" Stretch="UniformToFill" AutomationProperties.Name="{Binding Title}"/>
</Border>
<StackPanel Grid.Column="1" VerticalAlignment="Top" Margin="10,0,0,0">
<TextBlock Text="{Binding Nombre}" Style="{StaticResource TitleTextBlockStyle}" TextWrapping="NoWrap"/>
<CheckBox Grid.Column="0" IsChecked="{Binding Visibilidad, Mode=TwoWay}"/>
</StackPanel>
</Grid>
</DataTemplate>
</GridView.ItemTemplate>
</GridView>
And this is CS
Code:
private void itemGridView_SizeChanged(object sender, SizeChangedEventArgs e)
{
ItemsWrapGrid appItemsPanel = (ItemsWrapGrid)itemGridView.ItemsPanelRoot;
double optimizedWidth = 200;
var number = (int)e.NewSize.Width / (int)optimizedWidth;
var margenes= (e.NewSize.Width -number*optimizedWidth)/number/2;
Thickness dato = (Thickness)this.Resources["margenGrid"];
dato.Bottom = margenes;
dato.Left = margenes;
dato.Right = margenes;
dato.Top = margenes;
this.Resources["margenGrid"] = dato;
}
Thanks!!

Related

TwoLineListItem with icon

Hello!
I would like to ask you for help. I do not know how to create an custom adapter for TwoLineListItem with icon. I know how to set text using ListArray with HashMap. But how to add image (as @android:id/icon)?
Code:
String[][] ss = new String[][]{
{"string 1", "string 2"}
{"string 3", "string 4"}
{"string 5", "string 6"}};
List<HashMap<String,String>> list = new ArrayList<HashMap<String,String>>();
for(int i=0; i<ss.length;i++) {
HashMap<String,String> item = new HashMap<String,String>();
item.put("text1", ss[i][0]);
item.put("text2", ss[i][1]);
list.add(item);
}
ListAdapter adapter = new SimpleAdapter(this,
list,
R.layout.list_position_layout,
new String[] {"text1","text2"},
new int[] {android.R.id.text1, android.R.id.text2 });
setListAdapter(adapter);
I suppose that solution is very easy... But I do not know how to do it.

Android Code: Downloading from within an app

I've searched the android website but I cannot find any sample code that will allow you to download something from a webpage/website. I'm trying to create a simple application that will allow you to download a podcast from a website straight onto the phone's sdcard. Any help is appreciated. Thanks!
[Edit]: I've found http://developer.android.com/reference/android/webkit/DownloadListener.html it seems right but I'm still a beginner and not sure how to apply the code / modify it and where to place it.
Networking is a big series of tests. Just about everything needs to be within a try/catch block, and you need to think of and test every possible contingency. Without doing that, you WILL get crashes and ugliness.
It is not the simplest thing for a newb to implement.
The SECOND thing you need to note is that WEBKIT is not what you want to mess with for *pure downloads*. If you just want to pull a file and do something manual with it, you do NOT want to be messing with an html rendering engine (that's what webkit is...).
Third, network requests should be done in a SEPARATE THREAD from the UI, otherwise it will result in a terrible user experience, ANR's, and general appearance of FREEZUPS.
You can try some of this:
Code:
public class HTTPGetData {
private byte[] data;
public HTTPGetData(){
}
public byte[] toByteArray(){
return data;
}
public void getViaHttpConnection(String url) throws IOException{
HttpClient httpClient = new DefaultHttpClient();
Log.d("***HTTPGetData",url);
HttpGet request = new HttpGet(url);
request.addHeader("Accept-Encoding", "gzip");
HttpResponse response;
try {
response = httpClient.execute(request);
boolean gzip = false;
if (response.containsHeader("Content-Encoding")){
Header[] headers = response.getHeaders("Content-Encoding");
for (int i=0; i<headers.length; i++){
if (headers[i].getValue().compareToIgnoreCase("gzip")==0) gzip = true;
}
}
int status = response.getStatusLine().getStatusCode();
// we assume that the response body contains the error message
if (status != HttpStatus.SC_OK) {
ByteArrayOutputStream ostream = new ByteArrayOutputStream();
response.getEntity().writeTo(ostream);
Log.e("HTTP_CLIENT", ostream.toString());
throw new IOException("HTTP response code: " + status);
} else {
int len = (int)response.getEntity().getContentLength();
InputStream content;
if (gzip) content = new GZIPInputStream(response.getEntity().getContent());
else content = response.getEntity().getContent();
if (len>0 && !gzip){
byte[] theData = new byte[len];
int rec = 0;
int cread = 0;
boolean fail=false;
while (rec < len){
if ((cread=content.read(theData, rec, len-rec))==0){
Log.e("HTTP_CLIENT","Short");
fail=true;
break;
}
rec+=cread;
}
if (!fail) data=theData;
} else {
int ch;
ByteVector bv = new ByteVector(1000);
while ((ch = content.read()) != -1){
bv.add((byte)ch);
}
data = bv.toByteArray();
}
content.close(); // this will also close the connection
}
} catch (ClientProtocolException e) {
Log.e("HTTP_CLIENT","ClientProtocolException");
throw new IOException("ClientProtocolException caught in HTTPGetData.getViaHttpConnection(String url)");
} catch (IOException e) {
Log.e("HTTP_CLIENT","IOException");
throw new IOException("IOException caught in HTTPGetData.getViaHttpConnection(String url)");
}
}
}
What you can do with that is something like this;
try{
HTTPGetData hgd = new HTTPGetData();
hgd.getViaHttpConnection("http://someurl");
//open file and dump in hgd.toByteArray();
catch(IOException e){
//do something with e
}
... and of course, put that in some new thread and while its running, make something spin to give the user the impression of progress.
Thanks lb. I don't really understand perfectly but I will look up the stuff I do not understand. Thanks for the help

[Q] integrate region specific translation into an app

Hey,
my actually app integrates German translations into a specific app, with the following code:
Code:
...
Field[] fields = null;
try{
fields = R.string.class.getFields();
for(final Field field : fields) {
String name = field.getName();
try{
int id = field.getInt(R.string.class);
try { resparam.res.setReplacement(resparam.packageName, "string", name,modRes.getString(id)); } catch(RuntimeException e) { };
}catch (Exception ex) {
}
}
} catch(RuntimeException e) { };
...
Currently I'm trying to expand these translations for specific regions (e. g. de-AT, de-NL) but these resources, stored in "\res\values-de-rAT" (e. g.), aren't integrated into the desired app and i don't know why...
Any suggestions?
thanks
Nobody has a solution for this?
Gesendet von meinem Nokia 5110 mit ViperN und Tapatalk 7 Ultra HD

Posible wp registry editor from PC?

This tool http://go.microsoft.com/?linkid=9898656 (this is thedownload link) has an script inside atached to this message.
Can we modify windows phone registryfrom PC?
#################################################################################
# Grant/Deny the user access to the registry entry.
#################################################################################
function Add-RegistryPermission(
[String]$RegKeyPath = $(throw "No registry key path is specified"),
[String]$User = $(throw "No user is specified"),
[String]$Permission = $(throw "No permission is specified"),
[String]$AccessControlType = "Allow"
)
{
$acl = Get-Acl -Path $regkeyPath
$controlType = [Enum]:arse([Security.AccessControl.AccessControlType], $AccessControlType)
$iFlags = [Enum]:arse([Security.AccessControl.InheritanceFlags], "ContainerInherit,ObjectInherit")
$pFlags = [Enum]:arse([Security.AccessControl.PropagationFlags], "None")
$rights = [Enum]:arse([Security.AccessControl.RegistryRights], $Permission)
if($AccessControlType -eq "Allow")
{
$accesses = @($acl.Access | where {$_.IdentityReference -eq $User})
foreach($access in $accesses)
{
if($access.AccessControlType -eq 'Deny')
{
if(($access.RegistryRights.Value__ -band $rights.Value__) -ne 0)
{
$rule = New-Object Security.AccessControl.RegistryAccessRule $User,$access.RegistryRights,$iFlags,$pFlags,$access.AccessControlType
[void]$acl.RemoveAccessRule($rule)
}
}
}
}
$rule = New-Object Security.AccessControl.RegistryAccessRule $User,$rights,$iFlags,$pFlags,$controlType
$acl.AddAccessRule($rule)
$acl | Set-Acl
}
What makes you think this has anything to do with phone? That's a PowerShell script (which the phone can't execute) for editing the permissions on a registry key (which you can't do unless you already have control over that registry key anyhow, i.e. you would need to run it as Admin). It's not a registry "editor" at all, aside from changing a registry ACL. It might be handy for those who want to edit permissions on a PC registry key without opening regedit, but that's it.
Please don't post stuff like this in Dev&Hacking if you don't have any idea what it does. Also, please don't spam me with PMs about it. You've been here long enough that you should know better, even if my signature didn't specifically ask people not to waste my time that way. I have blocked you from messaging me.
You wasted my time...
<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://schemas.microsoft.com/embedded/2004/10/ImageUpdate">
<Identity>
<Owner>Microsoft</Owner>
<Component>MS_SLAPI_UPDATER_FEATURE_PACK</Component>
<SubComponent>MainOS</SubComponent>
<Version Major="8" Minor="10" QFE="15154" Build="166" />
</Identity>
<ReleaseType>Production</ReleaseType>
<OwnerType>Microsoft</OwnerType>
<BuildType>Retail</BuildType>
<CpuType>ARM</CpuType>
<Partition>MainOS</Partition>
<GroupingKey>MS_SLAPI_UPDATER_FEATURE_PACK</GroupingKey>
<IsRemoval>false</IsRemoval>
<Files>
<FileEntry>
<FileType>Manifest</FileType>
<DevicePath>\Windows\Packages\DsmFiles\Microsoft.MS_SLAPI_UPDATER_FEATURE_PACK.MainOS.dsm.xml</DevicePath>
<CabPath>man.dsm.xml</CabPath>
<Attributes>Archive</Attributes>
<FileSize>3652</FileSize>
<CompressedFileSize>3652</CompressedFileSize>
<StagedFileSize>895</StagedFileSize>
</FileEntry>
<FileEntry>
<FileType>SecurityPolicy</FileType>
<DevicePath>\Windows\Packages\PolicyFiles\Microsoft.BaseOS.SLAPIUpdater.Feature.policy.xml</DevicePath>
<CabPath>2_Microso.xml</CabPath>
<Attributes>Archive</Attributes>
<SourcePackage>Microsoft.BaseOS.SLAPIUpdater.Feature</SourcePackage>
<FileSize>1063</FileSize>
<CompressedFileSize>1063</CompressedFileSize>
<StagedFileSize>635</StagedFileSize>
</FileEntry>
<FileEntry>
<FileType>Registry</FileType>
<DevicePath>\Windows\Packages\RegistryFiles\Microsoft.MS_SLAPI_UPDATER_FEATURE_PACK.MainOS.reg</DevicePath>
<CabPath>6_Microso.reg</CabPath>
<Attributes>Archive Compressed</Attributes>
<FileSize>5482</FileSize>
<CompressedFileSize>4096</CompressedFileSize>
<StagedFileSize>1245</StagedFileSize>
</FileEntry>
<FileEntry>
<FileType>Catalog</FileType>
<DevicePath>\Windows\System32\catroot\{F750E6C3-38EE-11D1-85E5-00C04FC295EE}\Microsoft.MS_SLAPI_UPDATER_FEATURE_PACK.MainOS.cat</DevicePath>
<CabPath>content.cat</CabPath>
<Attributes>Archive Compressed</Attributes>
<FileSize>5064</FileSize>
<CompressedFileSize>4096</CompressedFileSize>
<StagedFileSize>3307</StagedFileSize>
</FileEntry>
<FileEntry>
<FileType>Regular</FileType>
<DevicePath>\windows\System32\ETWSLAPIUpdater.dll</DevicePath>
<CabPath>3_ETWSLAP.dll</CabPath>
<Attributes>Archive Compressed</Attributes>
<SourcePackage>Microsoft.BaseOS.SLAPIUpdater.Feature</SourcePackage>
<FileSize>8192</FileSize>
<CompressedFileSize>4096</CompressedFileSize>
<StagedFileSize>727</StagedFileSize>
</FileEntry>
<FileEntry>
<FileType>Regular</FileType>
<DevicePath>\windows\System32\SLAPIUpdater.exe</DevicePath>
<CabPath>4_SLAPIUp.exe</CabPath>
<Attributes>Archive Compressed</Attributes>
<SourcePackage>Microsoft.BaseOS.SLAPIUpdater.Feature</SourcePackage>
<FileSize>36608</FileSize>
<CompressedFileSize>16384</CompressedFileSize>
<StagedFileSize>11970</StagedFileSize>
</FileEntry>
<FileEntry>
<FileType>Regular</FileType>
<DevicePath>\windows\System32\UpdateKernelCache.exe</DevicePath>
<CabPath>5_UpdateK.exe</CabPath>
<Attributes>Archive Compressed</Attributes>
<SourcePackage>Microsoft.BaseOS.SLAPIUpdater.Feature</SourcePackage>
<FileSize>57648</FileSize>
<CompressedFileSize>36864</CompressedFileSize>
<StagedFileSize>30446</StagedFileSize>
</FileEntry>
</Files>
</Package>
Reg file inside executable:
Windows Registry Editor Version 5.00
; RegistrySource=Microsoft.BaseOS.SLAPIUpdater.Feature.reg
[HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\WINEVT\Publishers\{6D00F5E7-D43C-42A7-87A9-166745D22A21}]
@="Microsoft-WindowsPhone-SLAPIUpdater"
"Enabled"=dword:00000001
;Value:C:\windows\System32\ETWSLAPIUpdater.dll
"MessageFileName"=hex(2):43,00,3A,00,5C,00,77,00,69,00,6E,00,64,00,6F,00,77,00,73,00,5C,00,53,00,79,00,73,00,74,00,65,00,6D,00,33,00,32,00,5C,00,\
45,00,54,00,57,00,53,00,4C,00,41,00,50,00,49,00,55,00,70,00,64,00,61,00,74,00,65,00,72,00,2E,00,64,00,6C,00,6C,00,00,00
;Value:C:\windows\System32\ETWSLAPIUpdater.dll
"ResourceFileName"=hex(2):43,00,3A,00,5C,00,77,00,69,00,6E,00,64,00,6F,00,77,00,73,00,5C,00,53,00,79,00,73,00,74,00,65,00,6D,00,33,00,32,00,5C,00,\
45,00,54,00,57,00,53,00,4C,00,41,00,50,00,49,00,55,00,70,00,64,00,61,00,74,00,65,00,72,00,2E,00,64,00,6C,00,6C,00,00,00
[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\WMI\Autologger\WinPhoneCritical\{6D00F5E7-D43C-42A7-87A9-166745D22A21}]
"Enabled"=dword:00000001
"EnableLevel"=dword:00000004
;Value:0X0000000000000005
"MatchAnyKeyword"=hex(b):05,00,00,00,00,00,00,00
; RegistrySource=Microsoft.BaseOS.SLAPIUpdater.Schedule.reg
[HKEY_LOCAL_MACHINE\Software\Microsoft\WPTaskScheduler\{1A6FC98F-6F1F-427A-8059-F51F520BAAF7}]
"Schedule"=hex:01,10,08,00,CC,CC,CC,CC,B0,01,00,00,00,00,00,00,00,00,02,00,01,00,00,00,04,00,02,00,2E,06,02,00,00,00,18,00,00,00,00,00,\
00,00,00,00,0F,27,0C,00,00,00,1F,00,00,00,00,00,00,00,00,00,FF,FF,FF,FF,08,00,02,00,28,00,02,00,00,00,00,00,8F,C9,6F,1A,\
1F,6F,7A,42,80,59,F5,1F,52,0B,AA,F7,01,01,00,00,00,00,00,00,22,00,00,00,42,00,61,00,73,00,65,00,4F,00,53,00,5F,00,54,00,\
61,00,73,00,6B,00,50,00,72,00,6F,00,76,00,69,00,73,00,69,00,6F,00,6E,00,5F,00,53,00,4C,00,41,00,50,00,49,00,55,00,70,00,\
64,00,61,00,74,00,65,00,72,00,00,00,02,00,02,00,0C,00,02,00,01,00,00,00,03,00,00,00,10,00,02,00,03,00,00,00,01,00,01,00,\
14,00,02,00,01,00,01,00,1C,00,02,00,01,00,01,00,24,00,02,00,75,90,BC,A3,22,1D,C6,41,02,00,00,00,04,00,00,00,18,00,02,00,\
00,00,00,00,00,00,00,00,04,00,00,00,00,00,00,00,75,38,BC,A3,3E,06,8A,41,02,00,00,00,04,00,00,00,20,00,02,00,00,00,00,00,\
00,00,00,00,04,00,00,00,00,00,00,00,75,50,BC,A3,3E,06,8A,41,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\
00,00,00,00,2C,00,02,00,30,00,02,00,00,00,00,00,30,00,00,00,00,00,00,00,30,00,00,00,25,00,73,00,79,00,73,00,74,00,65,00,\
6D,00,64,00,72,00,69,00,76,00,65,00,25,00,5C,00,77,00,69,00,6E,00,64,00,6F,00,77,00,73,00,5C,00,73,00,79,00,73,00,74,00,\
65,00,6D,00,33,00,32,00,5C,00,53,00,4C,00,41,00,50,00,49,00,55,00,70,00,64,00,61,00,74,00,65,00,72,00,2E,00,65,00,78,00,\
65,00,00,00,00,00,00,00

Help enabling downloads through webview (Kotlin)

Good day. I'm new to android development and I'm trying to develop a simple webview application, picked a nice template and went through the steps and made good progress, I managed to load my site fully and enable javascript, that works as intended, however I'm not able to make the app download anything, I host a few pdf files that should open or download through it, but nothing happens.
I looked at a few answers here and it is to my understanding that I need to specifically add a function for that, could you give me a hand? I have tried multiple different code and tweaking them, but I wasn't able to get it to work, here is my base code:
Code:
package com.logista.test.ui.home
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.webkit.WebResourceRequest
import android.webkit.WebView
import android.webkit.WebViewClient
import android.app.DownloadManager
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProvider
import com.logista.test.R
class HomeFragment : Fragment() {
private lateinit var homeViewModel: HomeViewModel
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
homeViewModel =
ViewModelProvider(this).get(HomeViewModel::class.java)
val root = inflater.inflate(R.layout.fragment_home, container, false)
val myWebView: WebView = root.findViewById(R.id.webview)
myWebView.webViewClient = WebViewClient()
myWebView.settings.javaScriptEnabled = true
myWebView.loadUrl("https://www.example.org/")
return root
}
}
I believe I should be adding
Code:
import android.app.DownloadManager
And tweak this
Code:
// Set web view download listener
web_view.setDownloadListener(DownloadListener {
url,
userAgent,
contentDescription,
mimetype,
contentLength ->
// Initialize download request
val request = DownloadManager.Request(Uri.parse(url))
// Get the cookie
val cookies = CookieManager.getInstance().getCookie(url)
// Add the download request header
request.addRequestHeader("Cookie",cookies)
request.addRequestHeader("User-Agent",userAgent)
// Set download request description
request.setDescription("Downloading requested file....")
// Set download request mime tytpe
request.setMimeType(mimetype)
// Allow scanning
request.allowScanningByMediaScanner()
// Download request notification setting
request.setNotificationVisibility(
DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
// Guess the file name
val fileName = URLUtil.guessFileName(url, contentDescription, mimetype)
// Set a destination storage for downloaded file
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, fileName)
// Set request title
request.setTitle(URLUtil.guessFileName(url, contentDescription, mimetype));
// DownloadManager request more settings
request.setAllowedOverMetered(true)
request.setAllowedOverRoaming(false)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
request.setRequiresCharging(false)
request.setRequiresDeviceIdle(false)
}
request.setVisibleInDownloadsUi(true)
// Get the system download service
val dManager = getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager
// Finally, request the download to system download service
dManager.enqueue(request)
})
// Load button click listener
button_load.setOnClickListener{
// Load url in a web view
web_view.loadUrl(url)
}
}
Taken from here: https://android--code.blogspot.com/2018/03/android-kotlin-webview-file-download.html
I did the basics, renaming the function accordingly and such, but it gives me quite a few errors when building the app, for instance uri isn't defined, cookiemanager isn't defined, environment isn't defined, build isn't defined, and such, could you give me some guidance?

Categories

Resources